【发布时间】:2015-06-10 13:00:53
【问题描述】:
自从我开始使用 Swiftmailer 以来,我一直遇到这个问题。我知道我是新手,所以可能做错了什么。任何帮助将不胜感激。
问题是: 我只在 GMAIL 中收到空白正文,但在 OUTLOOK/YAHOO 中收到所有内容。
我不确定问题是什么。提前感谢您的回答。
这里我调用函数来发送包含所有属性的电子邮件
$subject = "CROCT Admin - Evaluate performance of participant for project - '".$result2['project_name']."'";
$from = array('test@test.com' => 'Tasty');
$to = $result4[$i]['email'];
$body = 'Hello, You have got an invitiation to participate your work in project '.$result2['project_name'].' Accept the invitation and start participating in it.' .anchor('https://example.org/'.$project_id_url.'/'.$result4[$i]['user_id'], 'Accept Invitation');
$addpart = 'Best,Team CROCT';
$this->**send_email($subject, $from, $to, $body, $addpart)**;
这里是发送邮件的函数
function send_email($subject, $from, $to, $body, $addpart)
{
require_once APPPATH.'libraries/swift_mailer/swift_required.php';
//Create the Transport
$transport = Swift_MailTransport::newInstance();
/*
You could alternatively use a different transport such as Sendmail or Mail:
//Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
//Mail
$transport = Swift_MailTransport::newInstance();
*/
//Create the message
$message = Swift_Message::newInstance();
//Give the message a subject
$message->setSubject($subject)
->setFrom($from)
->setTo($to)
->setBody($body, 'text/plain')
->addPart($addpart, 'text/html')
;
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
if ($result) {
$this->session->set_flashdata('error', 'Invitation sent.');
} else {
$this->session->set_flashdata('error', 'Error occured.');
}
}
这就是我在 Gmail 中接收的方式
这就是我在 Outlook 中接收的方式
【问题讨论】:
-
您能否尝试删除
->addPart($addpart, 'text/html')并将其发送到 gmail。你的结果是什么? -
Ahhhaaa... 成功了。但结果给了我这个。 您好,您已收到邀请参与项目测试的工作,并开始参与。
Example.com">Accept邀请 @JamieSterling -
尝试更改
->setBody($body, 'text/html')并在您的$body中将$addpart内容放入其中,不要使用->addpart部分。我不会给你答案。 -
已通过将 $body 更改为 text/html 解决了这个问题。但现在我收到一封转发的电子邮件。我收到的所有文本都是引用文本。 @JamieSterling
标签: php email gmail swiftmailer