Swiftmailer won't send mail, but mail() will
Asked Answered
C

1

4

PHP's mail() function sends mail fine, but Swiftmailer's Swift_MailTransport doesn't work!

This works:

mail('[email protected]', 'test '.date('H:i:s'), '');

But this does not:

$transport = Swift_MailTransport::newInstance('');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('test '.date('H:i:s'))
  ->setFrom('[email protected]')
  ->setTo('[email protected]')
  ->setBody('Testing one two three');
$result = $mailer->send($message);

(The [email protected] is replaced by a valid email address in my test code.)

The mail logs for both events look very similar in both cases, and it appears that mail is being sent in the latter.

Could there be something about the message constructed by Swiftmailer that is causing it to be blocked by a spam filter?

(By the way, I have tried using the SMTP transport, with no luck; I figured that since mail() works correctly, it would be trivial to switch to Swiftmail's Mail transport...)

Civic answered 24/8, 2010 at 1:23 Comment(3)
Same problem here. I activated the logger Plugin but it did not print anything at all.Highbinder
I asked this question again: https://mcmap.net/q/1251052/-swiftmailer-does-not-send-mail-why/956397Highbinder
Possible duplicate of SwiftMailer does not send mail, why?Plumb
T
-3

Which mail server are you using(like your web server or gmail,yahoo..) this 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('[email protected]')
          ->setTo('[email protected]')
          ->setBody('Testing one two three');
$result = $mailer->send($message);

if mail() function works, then SwiftMailer should also work. Hope it worked for you, and helped you.

Thinia answered 21/9, 2010 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.