【问题标题】:Email body is blank when receiving it in GMAIL - Swiftmailer在 GMAIL 中接收电子邮件正文时为空白 - Swiftmailer
【发布时间】: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 中接收的方式

This is I received after change

【问题讨论】:

  • 您能否尝试删除 ->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


【解决方案1】:

对于 cmets,这应该被所有主要的电子邮件提供商接受。

测试:

  • 邮箱
  • 展望
  • 雅虎
  • kerio

邮件功能:

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/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.');
            }
        }

属性:

$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').'<br>Best,Team CROCT';
$this->**send_email($subject, $from, $to, $body)**;

【讨论】:

  • 那行得通。但不确定如何处理电子邮件中引用的文本。它看起来像转发的电子邮件。我添加了有问题的图像。 @JamieSterling
  • 这些是单引号还是双引号?可以添加屏幕截图的链接
  • 我没找到你。链接到哪里?我在问题中添加了屏幕截图。 @jamiesterling
  • 引用的邮件,上传新邮件的截图到这里imgur.com评论链接
  • 添加有问题。也在这里添加[链接]i.stack.imgur.com/kTwKt.jpg@jamiesterling
猜你喜欢
  • 1970-01-01
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多