Why doesn't SwiftMailer send mail?

SwiftMail does not send my email, and mail() works. Same as here .

I added EchoLogger but didn't 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 letter returns to $failures , but why?

Update

In Swift_Transport_SimpleMailInvoker::mail I reset the parameters and received the following:

  $headers => string(208) "Message-ID: < 1337173064.4fb3a4480b8dd@domain.de > Date: Wed, 16 May 2012 14:57:44 +0200 From: news@domain.de MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable " $extraParams => string(15) " -fnews@domain.de " 

$to, $subject, $body is the same as I used in mail() . I don’t know what the problem is yet.

Update # 2

This worked fine for me:

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

Disclaimer This is not a solution, but a workaround that I used because I did not have time to debug the framework and find a real solution. Feel free to use the above information to debug yourself and post your solution here. I will gladly agree and support him.

+7
source share
7 answers

I had the same problem.

According to the documentation of swiftmailer.org, by default, Swift_MailTransport :: newInstance () uses the -f%s options, which is why you got " -fnews@domain.de " to solve this empty space between -f %s .

Now your code may look like this: $message = Swift_Message::newInstance('-f %s') ;

I solved this problem by simply passing null to __construct (). So my working code looks like this:

$message = Swift_Message::newInstance(null) ;

I hope this helps someone.

PS I use Postfix to send emails.

+5
source

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

If you cannot use the debugger, you should look at the mail function in lib/classes/Swift/Transport/SimpleMailInvoker.php . There is a call to the internal mail function with the shutup operator ('@'). Perhaps deleting this statement may show you an error message. You can also use var_dump() to reset the parameters passed there.

+7
source

I was able to fix it. I used noReply@mydomain.com from the header and this email account was not created. I created noReply@mydomain.com and my emails started to work. Hope this helps someone.

+6
source

It looks like you are using the default transport mechanism, which according to their documents uses mail() by default.

Serious disadvantages when using this transport are:

  • Unpredictable message headers
  • No feedback on delivery failures
  • Lack of support for multiple plugins requiring real-time delivery feedback

a source

If I debugged this, I would find the SwiftMailer implementation of the mail() function and discard the arguments passed to them and compare them with your own working version of mail() . I have no experience with SwiftMailer, but this seems like a quick option.

+2
source

The problem is Swift_Transport_MailTransport, private $_extraParams = '-f%s' .

In some situations, the '-f' flag (see your code: string(15) " -fnews@domain.de " ). Igniter code has the same "error".

+1
source

I learned about symfony if I just exit the function with "exit ()", for example, swiftmailer will not send mail, but if I ended up with

return a new answer (); he sends a fine. so i'm not sure.

0
source

It can be really old. Had the same problem been resolved by using the shorter of the email. seems to be the maximum length after the @ 10 sign. This is what I have tested so far.

Example:

 $sname = ' noreply@system.com '; ->setFrom(array($sname => 'Some Header Title here')); 
-2
source

All Articles