我在我的 PHP 脚本中使用SwiftMailer来发送电子邮件,并使用TinyMCE作为文本编辑器来编写和格式化消息正文。问题是,当我发送消息时,它在所有电子邮件客户端(gmail、yahoo 和 hotmail)中都没有任何格式显示,甚至链接也不显示为链接,它们显示为普通文本,但显示为蓝色。那么问题是什么?
这是我用来发送电子邮件的代码:
<?php
require_once 'path/to/SwiftMailer/lib/swift_required.php';
$transport = Swift_MailTransport::newInstance();
# Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
# Create the message
$msg = Swift_Message::newInstance();
# Give the message a subject
$msg->setSubject($_POST['subject']);
# Set the From address with an associative array
$msg->setFrom(array($_POST['sender_email'] => $_POST['sender_name']));
# Give it a body
$msg->setBody($_POST['message'], 'text/html');
$failedRecipients = array();
$numSent = 0;
$to = array(
'recipient_1@gmail.com',
'recipient_2@yahoo.com' => 'Recipient 2',
'recipient_3@hotmail.com',
'recipient_4@gmail.com' => 'Recipient 4',
'recipient_5@yahoo.com'
);
foreach ($to as $address => $name) {
if (is_int($address)) {
$msg->setTo($name);
} else {
$msg->setTo(array($address => $name));
}
$numSent += $mailer->send($msg, $failedRecipients);
}
echo $numSent > 0 ? 'SUCCESS' : 'FAILURE';
?>
请注意,它$_POST['message']
包含我使用 TinyMCE 编写和格式化的消息正文。