我到處都找過這個問題,而我對這個發現是增加以下內容:添加風格的PHP的HTML電子郵件
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
和
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
我想送通訊類型的電子郵件,所以造型真的很重要。我看到的所有視頻都只是製作HTML表單,所以我真的沒有那麼做。我想在我的電子郵件中設置內容的樣式。
我現在有這個權利:
$to = $newsletter_email;
$subject = 'Thank you for subscribing';
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
#email-wrap {
background: #151515;
color: #FFF;
}
</style>
</head>
<body>
<div id="email-wrap">
<p>Hi,</p><br>
<p>Thank you.</p><br>
<p>Thank you,</p>
<p>Administration</p>
</div>
</body>
</html>
';
$from = "[email protected]";
//$Bcc = "[email protected]";
// 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: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
// $headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
我試圖從這個消息變量取出風格,把這個文件轉換爲HTML風格的文件時,PHP之外:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Newsletter</title>
<style>
#email-wrap {
background: #151515;
color: #FFF;
}
</style>
</head>
等
電子郵件實際發送,但我不知道如何添加樣式。我究竟做錯了什麼??
$email_from = "[email protected]";
$full_name = 'Company Name';
//$from_mail = $full_name.'<'.$email_from.'>';
$from = $from_mail;
//$from = "[email protected]";
//$Bcc = "[email protected]";
// To send HTML mail, the Content-type header must be set
$headers .= "From: ".$full_name." <".$email_from.">\r\n";
and $headers .= "Return-Path: ".$full_name." <".$email_from.">\r\n";
/*$headers = "" .
"Reply-To:" . $from . "\r\n" .
"X-Mailer: PHP/" . phpversion();*/
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from_email. "\r\n";
// $headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
電子郵件支持內聯css.use內嵌css的郵件設計。 – meet
請注意,您的代碼(以及所有發佈的答案)很容易遭受標頭注入攻擊(可能是其他攻擊),並且不會正確編碼電子郵件內容。不要推出自己的電子郵件代碼,你會做錯的,因爲所有這些都證明了這一點。使用一個像[PHPMailer](https://github.com/PHPMailer/PHPMailer)這樣的庫來標記這個問題。 – Synchro
您的字符集應該同意 - 您在HTML中設置UTF-8,但在郵件標題中設置ISO-8859-1;你不能同時擁有兩個 - 一旦你有非ASCII文本就會中斷 – Synchro