Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email help - php mail() or SMTP

I have a newsletter script which loops through members and sends a mail to each individually. this was running ok previously, but as the numbers have increased, the script has started to crash part way through. I'm using SwiftMailer and the message I'm getting is "sending failed using mail() as PHP's default mail()". Would there be any benefit to trying to send with SMTP instead of the native mail() function? Or should I be looking at another solution. Thanks for any pointers.

like image 689
tferdo Avatar asked Mar 14 '26 14:03

tferdo


2 Answers

The mail() function doesn't deliver mail, actually. It just hands over the mail you generated to the system's SMTP server. Either way, you're going to be using SMTP.

If swiftmailer is using PHP's mail() function, then most likely something's gone screwy with your system's SMTP setup. Check system logs (the maillog in particular) for clues, and see if Swiftmailer will give you any better error messages.

like image 140
Marc B Avatar answered Mar 16 '26 03:03

Marc B


According to the suggestions of the smart guy who developed Swiftmail and proabably banged his head on these issues (in order to avoid you and me to do the same), it might help you to use SMTP and not mail transport

In my experience -- and others' -- the mail() function is not particularly predictable, or helpful.

Quite notably, the mail() function behaves entirely differently between Linux and Windows servers. On linux it uses sendmail, but on Windows it uses SMTP. ...

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

It's a last resort, and we say that with a passion!

Moreover on the same page he also explains how to handle newsletters by simply iterating over the to field instead read section Sending Emails in Batch on the same page

like image 24
Marco Demaio Avatar answered Mar 16 '26 03:03

Marco Demaio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!