【发布时间】:2017-10-25 13:46:32
【问题描述】:
我正在发送 HTML 电子邮件并在 gmail 中获得不同的结果。
这就是我正在接受的Mintmail
我也想要 gmail 中的 mintmail 邮件。 注意字符间距和字体的区别(标题字体:Oswald 和副标题字体:Vollkorn)。
这是我发送邮件的 PHP 代码,
$to = $email_to;
$subject = 'Welcome to Codebreak!';
$from = $email_from;
// Headers for the HTML email
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Email body
$message = '';
$message .= '<html><head>';
$message .= '<meta charset=utf-8>';
$message .= '<link href=//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css rel=stylesheet integrity=sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN crossorigin=anonymous>';
$message .= '<link href=https://fonts.googleapis.com/css?family=Alfa+Slab+One|Open+Sans|Chivo:900|Playfair+Display:700|Roboto:400,300,500,700|Oswald:400,500,600,700|Vollkorn:400,700 rel=stylesheet>';
$message .= '</head><body>';
$message .= '<div class=main_container style=width:80%;margin:0 auto;>';
$message .= '<div class=top_red style=padding:15px;background-color:#E74C3C;color:#fff;><div class=mail_icon style=margin-left:auto;margin-right:auto;width:150px;><img src=images/email.png height=150px width=150px></div><div class=texts style=text-align:center;><h2 style=font-family:Oswald,sans-serif;font-size:45px;color:#fff;margin-bottom:10px;margin-top:5px;>HEY, '.$first_name_to.'!</h2><h3 style=font-family:Vollkorn,serif;font-size:25px;font-weight:normal;margin-top:10px;>Welcome to the Codebreak family! :)</h3></div></div>';
$message .= '</div></body></html>';
mail($to, $subject, $message, $headers);
我尝试修改内联 CSS 并尝试在它们周围添加双引号(实际上我删除了双引号,因为 Gmail 正在向它们添加转义字符)。我的解决方案都不起作用,有人可以帮忙吗?
【问题讨论】:
-
使用基于表格的结构,它将帮助您在大多数电子邮件上保持相同的结构。
-
呼应 Himanshu 的评论。在电子邮件中使用 PHP 通常不会统一工作。坚持 XHTML 标准,在大多数电子邮件客户端中实现纯一对一。 HTML5 有点统一,但肯定有一些元素不能正常工作。
-
避免在电子邮件中使用自定义字体,并内联所有 CSS。
标签: php css html-email