我四处寻找这个问题,我发现的只是添加以下内容:
$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 = "newsletter@example.com";
//$Bcc = "example@example.com";
// 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 = "newsletter@example.com";
$full_name = 'Company Name';
//$from_mail = $full_name.'<'.$email_from.'>';
$from = $from_mail;
//$from = "newsletter@example.com";
//$Bcc = "example@example.com";
// 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);
最佳答案
您需要使用内联样式才能在您的电子邮件中使用
$to = $newsletter_email;
$subject = 'Thank you for subscribing';
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div id="email-wrap" style='background: #151515;color: #FFF;'>
<p>Hi,</p><br>
<p>Thank you.</p><br>
<p>Thank you,</p>
<p>Administration</p>
</div>
</body>
</html>
';
$from = "newsletter@example.com";
//$Bcc = "example@example.com";
// 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);
对于你问题的第二部分,你可以使用这样的东西
$to = 'test@server.com';
$email_from = "best.buy@yahoo.com";
$full_name = 'Best Buy';
$from_mail = $full_name.'<'.$email_from.'>';
$from = $from_mail;
$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";
$headers .= 'From: ' . $from_email . "\r\n";
mail($to,$subject,$message,$headers);
关于php - 向 php html 电子邮件添加样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35667790/