在GMAIL - Swiftmailer中收到邮件正文时,它是空白的

时间:2015-06-10 13:00:53

标签: php email 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中收到的信息 Result I am getting in email - Just for GMAIL

我在Outlook中收到的方式 This is what I receive in OUTLOOK

This is I received after change enter image description here

1 个答案:

答案 0 :(得分:1)

关于评论,所有主要电子邮件提供商都应该接受这一点。

经过测试:

  • gmail
  • 雅虎
  • 的Kerio

MailFunction:

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)**;