簡體   English   中英

為什么 html 沒有顯示在我使用 php mail() function 發送的 email 中?

[英]Why html not showing in the email i sent using php mail() function?

我使用 php mail() function 發送了 email 確認消息,但它沒有處理 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);

您可能需要為 html email 添加標頭。這是來自 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);

您需要在 header 中指定這是一個 html email,因此它將被解釋為 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);

可以考慮使用外部庫來處理HTML email。我以前成功使用過http://swiftmailer.org/

$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";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM