SwiftMailer does not send mail, why?

PiTheNumber picture PiTheNumber · May 16, 2012 · Viewed 29.3k times · Source

SwiftMail does not send my email, while mail() does work. Same as here.

I added the EchoLogger but it does not print anything.

$message = Swift_Message::newInstance();
$message->setSubject('Test');
$message->setTo( $email );
$message->setFrom(ABSENDER);
$message->setBody($nl_text);

$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);

$logger = new Swift_Plugins_Loggers_EchoLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));

$result = $mailer->send($message, $failures);
var_dump($failures);

The email is returned in $failures but why?

Update

In Swift_Transport_SimpleMailInvoker::mail I dumped out the parameters and got this:

  $headers =>
  string(208) "Message-ID: <[email protected]>
Date: Wed, 16 May 2012 14:57:44 +0200
From: [email protected]
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
"
  $extraParams =>
  string(15) "[email protected]"

$to, $subject, $body is same as I used in mail(). Still no idea what the problem is.

Update #2

This worked fine for me:

mail($email, 'Test', $nl_text, "From: " . ABSENDER);

Disclaimer: This is not a solution but the workaround I used, because I did not have the time to debugger the framework and find a real solution. Feel free to use the information given above to debug yourself and post your solution here. I will gladly accept and upvote it.

Answer

Alex picture Alex · May 16, 2012

I suggest you use the debugger and step to through the code behind send().

If you can not use a debugger you should have a look at the function mail in lib/classes/Swift/Transport/SimpleMailInvoker.php. There is a call to the internal mail function with an shutup operator (´@´). Maybe removing this operator can show you an error message. Also you can use var_dump() to dump the parameters passed there.