dqwnxdhb88531 2015-11-17 06:21
浏览 15
已采纳

将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

  • 写回答

2条回答 默认 最新

  • dongtan2603 2015-11-17 06:33
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dongroufan6846 2015-11-17 06:26
    关注

    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.
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab+波形匹配算法
  • ¥15 转录组分析做聚类树图时癌旁组被分到了癌组
  • ¥15 大一Python字典
  • ¥15 multisim电路设计(相关搜索:设计报告)
  • ¥15 PC-lint Plus
  • ¥15 gpl24676注释
  • ¥15 php5.3内存泄露
  • ¥15 DigSilent如何复制复合模型到自己案例?
  • ¥15 求日版华为b610s-77a 官方公版固件,有偿
  • ¥15 关于#java#的问题,请各位专家解答!(相关搜索:java程序)