我正在尝试通过PHP发送HTML邮件,但我似乎无法使其正常工作。
这是我的代码:
// multiple recipients
$to = 'mail';
// subject
$subject = 'Subject';
// message
$message = "
<html>
<head>
<title>Thanks</title>
</head>
<body>
<div>
<b>Thanks for your email</b>
</div>
</body>
</html>
";
// 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: info <info@example.com>' . "\r\n";
$headers .= 'From: Pynix <info@example.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
当我在Outlook中收到发件人时,这也不会显示任何发件人。
有人有想法吗?
由于
答案 0 :(得分:1)
我认为您不必将To:
行放在标题中,因为它是mail
函数的参数。
但是有些邮件客户端不喜欢轻型标题,这是我的工作:
$header = 'From: "Contact" <mail>'.PHP_EOL.
'Reply-to: <mail>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-Type: text/plain; charset=utf-8'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
答案 1 :(得分:0)
我使用SwiftMailer:
require_once('../lib/swiftMailer/lib/swift_required.php');
...
function sendEmail(){
//Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$body="Dear $fname,\n\nYour job application was successful. \n\nYours,\n\nEamorr\n\n\n\n\n\n\n";
//Create a message
$message = Swift_Message::newInstance('Subject goes here')
->setFrom(array($email => "no-reply@yourdomain.com"))
->setTo(array($email => "$fname $lname"))
->setBody($body);
//Send the message
$result = $mailer->send($message);
}
您可以轻松发送纯文本和HTML电子邮件。
答案 2 :(得分:0)
固定。
我发现这个由于某些原因在我的服务器上完美运行:
// Set The Headers:
$headers = 'From: "Me" <info@skillsexchangenetwork.net>'.PHP_EOL.
'Reply-to: <Me@Him.com>'.PHP_EOL.
'Cc: <Her @There.com>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-type: text/html; charset=iso-8859-1'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
// Send:
mail($to, $subject, $message, $headers);
感谢输入人员。