SwiftMailer does not send mail, why?

会有一股神秘感。 提交于 2019-12-05 03:31:04
VaL

I had the same problem.

According to the documentation swiftmailer.org by default Swift_MailTransport::newInstance() uses parameters -f%s and that is why you got "-fnews@domain.de", to solve that place blank space between -f %s.

Your code now can be looks like that: $message = Swift_Message::newInstance('-f %s');

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

$message = Swift_Message::newInstance(null);

I hope it will help someone.

P.S. I use Postfix to send emails.

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.

I was able to fix it. I was using noReply@mydomain.com in from header and this email account was not created. I created noReply@mydomain.com and my emails started working. I hope this helps somebody.

Looks like you're using the default transport mechanism which according to their docs uses mail() by default.

Serious drawbacks when using this Transport are :

  • Unpredictable message headers
  • Lack of feedback regarding delivery failures
  • Lack of support for several plugins that require real-time delivery feedback

source

If I were debugging this, I would find SwiftMailer's implementation of the mail() function and dump the arguments it's passing and compare them to your own working version of mail(). I don't have any experience with SwiftMailer but this seems like a fast option.

for_creator

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

The flag '-f' (see your code: string(15) "-fnews@domain.de") will fail in some situations. Code Igniter has the same "bug".

I found out on symfony if I just exit the function with "exit()" for example, swiftmailer won't send the mail but if I ended with

return new Response(); it sends fine. so I am not sure.

This may be really old, Had the same problem i solved it when using a shorter from email. seems like the maximum length after the @ sign is 10. that is what i have tested so far.

example:

$sname = 'noreply@system.com';
->setFrom(array($sname => 'Some Header Title here'));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!