Reaper0167 Posted July 10, 2009 Share Posted July 10, 2009 I have a varialbe which is randomly created that is sent to a user. Is there any way to use that variable inside the $message of the email script? The random number variable in my script is $code. <?php $message = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Thanks from mysite.com</title> </head> <body> <table width="500" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td height="74"><div align="center"> <p><img src="http://www.mysite.com/images/logo.png" width="335" height="93" /></p> <p><br> Forgot your password? Not a problem.<br /> In the box below you will find a security code.</p> [u] I would have the random number here inside the table [/u] <p align="center">Copy and paste that code into the space<br /> provided on this page<br /> http://www.mysite.com/request.php<br /> You can then update or change your password.</p> <p align="center">Thanks,<br /> mysite.com<br /> Happy Posting.</p> <p align="center"> </p> <p align="center">Please do not respond to this email. If you have a comment or question, please visit http://www.mysite.com</p> </div></td> </tr> </table> </body> </html> '; ?> Link to comment https://forums.phpfreaks.com/topic/165433-solved-using-a-varialbe-inside-a-php-email-script-with-html/ Share on other sites More sharing options...
joel24 Posted July 10, 2009 Share Posted July 10, 2009 you can either change the ' to ", so that php parses all the variables within the quotations... or wherever the variable goes you can put it in like '.$variable.' i.e. 1 $message = "This is the email script: $variable etc etc"; i.e. 2 $message = 'This is the email script: '.$variable.' etc etc'; Link to comment https://forums.phpfreaks.com/topic/165433-solved-using-a-varialbe-inside-a-php-email-script-with-html/#findComment-872549 Share on other sites More sharing options...
p2grace Posted July 10, 2009 Share Posted July 10, 2009 This is a perfect example of when heredoc works best. <?php $code = "ABC123"; $message = <<<MSG <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Thanks from mysite.com</title> </head> <body> <table width="500" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td height="74"><div align="center"> <p><img src="http://www.mysite.com/images/logo.png" width="335" height="93" /></p> <p><br> Forgot your password? Not a problem.<br /> In the box below you will find a security code.</p> <p>$code</p> <p align="center">Copy and paste that code into the space<br /> provided on this page<br /> http://www.mysite.com/request.php<br /> You can then update or change your password.</p> <p align="center">Thanks,<br /> mysite.com<br /> Happy Posting.</p> <p align="center"> </p> <p align="center">Please do not respond to this email. If you have a comment or question, please visit http://www.mysite.com</p> </div></td> </tr> </table> </body> </html> MSG; echo $message; ?> ?> Link to comment https://forums.phpfreaks.com/topic/165433-solved-using-a-varialbe-inside-a-php-email-script-with-html/#findComment-872555 Share on other sites More sharing options...
Reaper0167 Posted July 10, 2009 Author Share Posted July 10, 2009 thanks for the replies everyone, but I figured it out. something like this, $message = 'html stuff blah blah blah ' . $code . ' more html stuff'; So far this works ok. Link to comment https://forums.phpfreaks.com/topic/165433-solved-using-a-varialbe-inside-a-php-email-script-with-html/#findComment-872560 Share on other sites More sharing options...
p2grace Posted July 10, 2009 Share Posted July 10, 2009 I would still recommend using heredoc for simplicity. Link to comment https://forums.phpfreaks.com/topic/165433-solved-using-a-varialbe-inside-a-php-email-script-with-html/#findComment-872562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.