【发布时间】:2012-12-18 07:13:38
【问题描述】:
我正在通过我的 gmail 帐户使用 php 发送电子邮件。我使用的是ssmtp而不是sendmail。我正在使用以下 php 代码发送邮件。
$to = "mymail@gmail.com";
$from = "mymail@gmail.com";
$subject = "Testing mail";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
$headers = "From:" . $from;
$message = "<html><body><head></head>";
$message .= "<h1>Hello, World!</h1>";
$message .= "</body></html>";
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";
} else {
echo 'failed';
}
但我收到如下邮件
<html><body><head></head><h1>Hello, World!</h1></body></html>
这可能是什么原因?我在 Ubuntu 中使用 ssmtp MTA。
【问题讨论】:
-
Content-type: text/html; charset:应该是Content-type: text/html; charset= -
html 电子邮件是邪恶的。如今,它们是恶意软件感染的主要来源。不要使用它们。
-
您应该看看SwiftMailer 等库,它们是发送电子邮件的更清洁、更安全的方式。
-
将
$header更改为$headers,它应该可以工作