在 GMAIL - Swiftmailer 中接收时电子邮件正文为空白

Email body is blank when receiving it in GMAIL - Swiftmailer

自从我开始使用 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)**;

这里是send_mail

的函数
    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

至于评论,这应该被所有主要电子邮件提供商接受。

已测试:

  • gmail
  • 展望
  • 雅虎
  • 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)**;