我到处都找过这个问题,而我对这个发现是增加以下内容:添加风格的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