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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.