Swiftmailer will not send mail, but mail () will

The PHP mail () function sends mail in order, but Swiftmailer Swift_MailTransport does not work!

It works:

mail(' user@example.com ', 'test '.date('H:i:s'), ''); 

But this is not so:

 $transport = Swift_MailTransport::newInstance(''); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance('test '.date('H:i:s')) ->setFrom(' user@example.com ') ->setTo(' user@example.com ') ->setBody('Testing one two three'); $result = $mailer->send($message); 

( user@example.com is replaced with a valid email address in my test code.)

The mail logs for both events look very similar in both cases, and it seems that the mail is sent last.

Could there be something in the message generated by Swiftmailer that forces it to block the spam filter?

(By the way, I tried using the SMTP transport, no luck, I realized that since mail () works correctly, it would be trivial to switch to the Swiftmail Mail transport ...)

+4
source share
1 answer

Which mail server you use (for example, your web server or gmail, yahoo ..) is for gmail SMTP,

 $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl") ->setUsername($login_id) ->setPassword($password) ; $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance('test '.date('H:i:s')) ->setFrom(' user@example.com ') ->setTo(' user@example.com ') ->setBody('Testing one two three'); $result = $mailer->send($message); 

if the mail () function works, then SwiftMailer should also work. Hope this worked for you and helps you.

-3
source

All Articles