将Html插入邮件功能 - PHP

问题描述:

I am doing a reset password for a site i just felt like doing, Ok So What I Am trying to insert a HTML 'A' Tag into my $message Variable and show it in The Email i send out to where it will be a link

For Example:

$to = $torecoveremail;
$subject = "You Forgot Your Password At: " . $title;
$message = "
    Your Username: " . $recoverusername . "
    Your Email: " . $recoveruseremail . "
    Your First Name: " . $recoveruserfname . "
    Your Last Name: " . $recoveruserlname . "
    Reset Password Follow This Link:
    <a href=\"yourphotomake.info/shiylohs/cms/admin432/passreset.php?id=" . $passresetid . "\">Reset Password</a> ";
mail($to, $subject, $message);

and the out put from the email that is sent is:

Your Username: ben
    Your Email: ben@tvstartup.com
    Your First Name: ben
    Your Last Name: ben
    Reset Password Follow This Link:
    <a href="yourphotomake.info/shiylohs/cms/admin432/passreset.php?id=15">Reset Password</a>           

And what I want the email out put to be is this:

Your Username: ben
    Your Email: ben@tvstartup.com
    Your First Name: ben
    Your Last Name: ben
    Reset Password Follow This Link:
    Reset Password

Thank You A Lot

我正在为我想做的网站做一个重置密码,好吧我正试图插入一个 HTML'A'标记到我的 $ message code>变量并在电子邮件中显示它发送到它将成为链接的位置 p>

例如: p >

  $ to = $ torecoveremail; 
 $ subject =“你在忘记密码:”。  $ title; 
 $ message =“
您的用户名:”。  $ recoverusername。  “
您的电子邮件:”。  $ recoveruseremail。  “
你的名字:”。  $ recoveruserfname。  “
你的姓:”。  $ recoveruserlname。  “
重置密码关注此链接:
&lt; a href = \”yourphotomake.info/shiylohs/cms/admin432/passreset.php?id=“。$ passresetid。”\“&gt;重设密码&lt; / a&gt;  “; 
($ to,$ subject,$ message); 
  code>  pre> 
 
 

以及发送的电子邮件的输出结果为: p> 您的用户名:ben 您的电子邮件:ben@tvstartup.com 您的名字:ben 您的姓氏:ben 重置密码关注此链接: &lt; a href =“yourphotomake.info/shiylohs/cms/admin432/passreset.php?id=15”&gt;重置密码&lt; / a&gt; code> pre>

我想要的电子邮件是: p>

 您的用户名:ben 
 您的电子邮件:ben@tvstartup.com 
您的名字:ben 
您的姓氏:ben 
重置密码关注此链接:
重置密码
  code>  pre> 
 
 

非常感谢你 p> div>

You have specify headers.

$to = $torecoveremail;
$subject = "You Forgot Your Password At: " . $title;

$headers = "From: bob@example.com
";
$headers .= "CC: bob@example.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";

$message = '<html><body>';
$message .= '<p>Your Username: ben</p>';
$message .= '<p>Your Email: ben@tvstartup.com</p>';
$message .= '<p>Your First Name: ben</p>';
$message .= '<p>Your Last Name: ben</p>';
$message .= '<p>Reset Password Follow This Link:</p>';
$message .= '<p><a href="yourphotomake.info/shiylohs/cms/admin432/passreset.php?id=15">Reset Password</a></p>';
$message .= '</body></html>';

mail($to, $subject, $message, $headers);

For more options use PHPMAILER. Its very useful.

Be sure to include the Content-Type member in the 4th parameter. See the following example (slightly modified from php.net/mail):

<?PHP
$message = "<HTML><BODY><B>SOME HTML</B></BODY></HTML>";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "
";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "
";
$headers .= 'Cc: birthdayarchive@example.com' . "
";
$headers .= 'Bcc: birthdaycheck@example.com' . "
";

// Mail it
mail($to, $subject, $message, $headers);
?>

Also noted on PHP.net:

Note:

If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.