1

Possible Duplicate:
Why shouldn’t I use PHP’s mail() function?

In PHP, as long as i can send emails by using very simple mail() native function,

  • what is the good reason to use smtp?

Note: Please, I do not have enough knowledge in mail systems. So maybe i need a brief explanation about major differences in why using these two systems.

Community
  • 1
  • 1
夏期劇場
  • 17,821
  • 44
  • 135
  • 217
  • Also [Should I use php mail function or phpmailer?](http://stackoverflow.com/q/1231886) – Pekka Oct 12 '12 at 05:36

2 Answers2

1

mail() IS using SMTP in the background. it does not deliver the mail for you. When you call mail() PHP is simply handing the email over to your local system's SMTP system (sendmail, postfix, exim, etc...). Once the handoff is complete, PHP is out of the email game. It's up to the SMTP system to actually start the delivery process.

That being said, mail() is useful for quick and dirty simple emails. but anything moderately complicated (multiple recipients, mixed text/html emails, attachments, etc...) become highly tedious/complicated with just mail(), but quite simple when using a better smtp library, like PHPMailer or Swiftmailer.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • So you mean, the major usage benefit of `smtp` is having rich formatting and more email related functions (multiple recipients, attachments, etc...) ? – 夏期劇場 Oct 12 '12 at 05:40
  • are you talking about smtp the email sending protocol, or some php library named "smtp"? you can do formatting/attachments with basic mail(). it's simply far more complicated/error prone. – Marc B Oct 12 '12 at 05:42
1

Snippet from PHP manual :

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Add to this what Marc B said about the complexity (especially when you come to multipart) and I guess you've got your explanation.

Florian F.
  • 4,700
  • 26
  • 50