0

我使用 php mail() 函数发送了电子邮件确认消息,但它没有处理 html 标签。知道为什么吗?

   $content="Dear $name, <br /><br />Thank you for registering at NAME. Before we can activate your account one last step must be taken to confirm your email address .";
            $content.="<br /><br />Please note - you must complete this last step. You will only need to visit this URL once to confirm your email address.<br /><br />To complete your registration,";
            $content.=" please visit this URL:<br /><a href='$link1' target='_blank'> $link1 </a><br /><br /><br />";
            $content.="If you are still having problems signing up please contact a member of our support staff at&nbsp;<a href='mailto:email@gmail.com'>email</a> or contact our <a href='$link2'>customer care</a>. <br /><br />";
            $content.="All the best,<br />NAME<br />";
            mail($custArray['email'],"Please Confirm Your Email",$content);
4

4 回答 4

3

您可能需要为 html 电子邮件添加标题。这是来自 php 网站 ( http://php.net/manual/en/function.mail.php ) 的示例:

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

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

// Mail it
mail($to, $subject, $message, $headers);
于 2012-04-08T03:40:28.980 回答
3

您需要在标题中指定这是一封 html 电子邮件,以便将其解释为 html 而不是纯文本。

http://php.net/manual/en/function.mail.php

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$content="Dear $name, <br /><br />Thank you for registering at NAME. Before we can activate your account one last step must be taken to confirm your email address .";
$content.="<br /><br />Please note - you must complete this last step. You will only need to visit this URL once to confirm your email address.<br /><br />To complete your registration,";
$content.=" please visit this URL:<br /><a href='$link1' target='_blank'> $link1 </a><br /><br /><br />";
$content.="If you are still having problems signing up please contact a member of our support staff at&nbsp;<a href='mailto:email@gmail.com'>email</a> or contact our <a href='$link2'>customer care</a>. <br /><br />";
$content.="All the best,<br />NAME<br />";
mail($custArray['email'],"Please Confirm Your Email",$content, $headers);
于 2012-04-08T03:42:40.177 回答
1

您可以考虑使用外部库来处理 HTML 电子邮件。我过去曾成功使用过http://swiftmailer.org/

于 2012-04-08T08:51:24.863 回答
0
$headers  = "From: $email\r\n" . "Reply-To: $email\r\n" . "CC: $cc\r\n";

$message  = "$logmsg \r\n\n";
$message .= "Name : $name \r\n\n";
$message .= "Email : $email \r\n\n";
$message .= "Phone No : $phone \r\n\n";
于 2012-05-08T05:58:26.060 回答