Jump to content

[SOLVED] using a varialbe inside a php email script with html


Reaper0167

Recommended Posts

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>
';
?>

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';

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;
?>
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.