向php html电子邮件添加样式
我到处寻找这个问题,在这个问题上我发现的只是添加了以下内容:向php html电子邮件添加样式,php,html,css,email,phpmailer,Php,Html,Css,Email,Phpmailer,我到处寻找这个问题,在这个问题上我发现的只是添加了以下内容: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 及 我想发送一封时事通讯类型的电子邮件,所以样式对这件事很重要。我看的所有视频都只是制作html表单,所以我真的不明白。我想在我的电子邮件中设置内容的样式 我现在有这个: $to = $newsletter_em
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
及
我想发送一封时事通讯类型的电子邮件,所以样式对这件事很重要。我看的所有视频都只是制作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);
$to=$newsletter\u电子邮件;
$subject='谢谢订阅';
$message='1
#电子邮件包装{
背景:#151515;
颜色:#FFF;
}
您好,
谢谢。
谢谢,
管理
';
$from=”newsletter@example.com";
//$Bcc=”example@example.com";
//要发送HTML邮件,必须设置内容类型标题
$headers='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
//附加标题
$headers.='To:'。$To。“\r\n”;
$headers.='From:'。$From。“\r\n”;
//$headers.='Bcc:'。$Bcc。“\r\n”;
//发送电子邮件
邮件($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>
新闻稿
#电子邮件包装{
背景:#151515;
颜色:#FFF;
}
等等
这封邮件实际上是发送的,但我不知道如何给它添加风格。我做错了什么
$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);
$email\u from=”newsletter@example.com";
$full_name=‘公司名称’;
//$from_mail=$full_name.';
$from=$from_邮件;
//$from=”newsletter@example.com";
//$Bcc=”example@example.com";
//要发送HTML邮件,必须设置内容类型标题
$headers.=“From:”.$full\u name.\r\n”;
和$headers.=“返回路径:”.$full\u name.\r\n”;
/*$headers=”“。
“答复:”$从…起“\r\n”。
“X-Mailer:PHP/”。phpversion()*/
$headers='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
//附加标题
$headers.='To:'。$To。“\r\n”;
$headers.='From:'。$From_电子邮件。“\r\n”;
//$headers.='Bcc:'。$Bcc。“\r\n”;
//发送电子邮件
邮件($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=$newsletter\u电子邮件;
$subject='谢谢订阅';
$message='1
您好,
谢谢。
谢谢,
管理
';
$from=”newsletter@example.com";
//$Bcc=”example@example.com";
//要发送HTML邮件,必须设置内容类型标题
$headers='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
//附加标题
$headers.='To:'。$To。“\r\n”;
$headers.='From:'。$From。“\r\n”;
//$headers.='Bcc:'。$Bcc。“\r\n”;
//发送电子邮件
邮件($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);
$to='1!'test@server.com';
$email\u from=“最佳。buy@yahoo.com";
$full_name=‘百思买’;
$from_mail=$full_name.';
$from=$from_邮件;
$headers=”“。
“答复:”$从…起“\r\n”。
“X-Mailer:PHP/”。phpversion();
$headers.='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
$headers.='From:'$从你的电子邮件。“\r\n”;
邮件($to、$subject、$message、$headers);
事实上,您发送的电子邮件将以不同的方式打开,可以通过安装在机器上的电子邮件客户端(该客户端将集成HTML呈现引擎propriéaitre)打开,也可以通过在线电子邮件客户端(该客户端将以相当特殊的方式打开您的电子邮件并提取一些HTML属性)。
Campaign Monitor建议的表格为您提供了对损坏程度的快速概述,我们注意到,根据电子邮件客户端,规则是完全不同的。链接:
不过,也有一些工具,如内嵌的GulpCSS,可以将HTML样式转换为“在线”。
链接:试试看
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div style="background:#151515; color: #FFF;">
<p>Hi,</p><br>
<p>Thank you.</p><br>
<p>Thank you,</p>
<p>Administration</p>
</div>
</body>
</html>
您好,
谢谢。
谢谢,
管理
试着让它像模板一样
下面是一个可能有用的小例子
创建my_template.html文件并在该文件中添加以下代码
<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>
<body>
<p>Hi {{USERNAME}}</p>
<p>Please click on below link </p><br>
{{LINK}}
</body>
</html>
2) 替换变量
$link = "<a href='LINK YOU WANR TO PLACE'>Click Here </a>";
$html = str_replace("{{USERNAME}}",$username,$html);
$html = str_replace("{{LINK}}",$link,$html);
电子邮件支持内联css。使用内联css进行邮件设计。请注意,您的代码(以及所有发布的答案)容易受到标头注入攻击,可能会受到其他攻击,并且无法正确编码电子邮件内容。不要滚动你自己的电子邮件代码,你会做错的,所有这一切都证明了这一点;使用类似于您标记此问题的库。您的字符集应该同意-您在HTML中设置UTF-8,但在消息头中设置ISO-8859-1;你不能同时拥有这两种信息——一旦你拥有了非ascii文本,它就会崩溃。你知道为什么我的名字会在发送此信息时出现在新闻稿中吗?我想是的
$html = file_get_contents('my_template.html');
$link = "<a href='LINK YOU WANR TO PLACE'>Click Here </a>";
$html = str_replace("{{USERNAME}}",$username,$html);
$html = str_replace("{{LINK}}",$link,$html);
$from = "newsletter@example.com";
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$html,$headers);