FBP
FBP

Reputation: 345

Difference between PHP mail function and using email delivery service like Sendgrid, Mandrill

I am building a program and need to send multiple emails based on certain events. I have coded using the PHP mail function but was advised against its use.

Can somebody explain the difference between the workings of the PHP mail function vs using commercial services like Sendgrid, Mandrill etc? Why would one use these services when I can very well use the free PHP mail function to send mails?

Upvotes: 2

Views: 2092

Answers (5)

Dibya Sahoo
Dibya Sahoo

Reputation: 909

First of all, by profession I am a part of a global ESP "Pepipost" which helps brands in delivering the business critical triggered and transactional emails to their customers at the most .

But, the intend of myself here answering this question is not to promote an ESP over PHP mail function. I will share you some facts which we observed during our research at Pepipost Labs.

  1. PHP mail function is just a basic method/the core function to generate the email. But, it cannot deliver your emails at a scale, neither it can help in better deliverability, both of these are key to any businesses.

  2. With the evolution of more sophisticated technologies and algorithms, ISPs (Gmail, yahoo, Outlook and others) and Spam Filters are getting more and more smarter. Before reaching the mailbox, each email passes through all these filters where the content, reputation and other parameters are scanned. Hence, its very important to have good reputed IPs and envelope domains.

  3. Once the email reaches the recipient server either it will get deliver, throttle or bounce. In case of Bounce, Spam Complaint, Unsubscribe, the recipient server will communicate your server, and in that case you need to handle all these properly else the reputation of your domain and IP will goes down.

In case of throttling, another set of complex deliver logics required.

In short, if you are planning to send few hundred emails, then PHP mail function might be ok to use, but to scale further it's important to use a good ESP (Email Service Provider).

Upvotes: 0

Sylwester Zarębski
Sylwester Zarębski

Reputation: 415

Mail() function works very simply on *nix systems, it just executes local command sendmail to send message. It does have disadvantages like:

  • do not work in many cheap hosting environments
  • You do not have any information if message is accepted by sending MTA, it could be rejected or quarantined or stay forever in local queue
  • in some environments it could generate garbled headers because of wrong EOL characters (\r\r\n instead of \r\n)

I think You should use open source library like PHPMailer or Swift Mailer, because it has many more functionality besides simply sending mail. Some advantages of these libraries:

  • You could easily send HTML mail with attachments and images
  • You could send messages through external SMTP services
  • they have DKIM and S/MIME signing support

PS. I do not use commercial services like Sendgrid, Mandrill, thus can't compare.

Upvotes: -1

symcbean
symcbean

Reputation: 48357

Bulk mailing and campaign management is a complex organizational and technological challenge but will not be helped by most opensource php lib for emails (which simply add html formatting and support for attachments).

They won't handle IPR, SPF, spam trap avoidance, bounce handling, throttling, subscription management and more. Which good bulk emaillers provide.

If you know what you are doing, have full admin rights on your system and NS records and time to write the code, then, yes, you could build the same service - but its not just comparing ants to elephants - its comparing a spanner to an orange.

Upvotes: 2

Auris
Auris

Reputation: 1329

comparing mail() to commercial services is like comparing ant to elephant. mail() is good for some fast notifications from the server if you dont need lots of customisation, but if you want to do something like email campaigns you would have to do a lot of additional server setup and build tons of custom functionallity arround your mail() function. Commercial services are good for campaigns but not notifications (waste of money imho). Try using some opensource php lib for emails, that will have a lot of that custom functionality sorted for you.

Upvotes: 0

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

You cannot send bulk emails in one go using this function. For example, if you want to send emails to 100k users, you will have to iterate over the emails ids. Yes, you can use the cc though but what if you have a template where in every email the user name will be added like:

Dear User abc

You will have to send one by one. You can't achieve this burst email shoot feature in mail function unless you use multiple processes.

MailQueue is good but I have used it, it does the same things, saves the emails into the database and dequeues the emails and send them one by one.

Again we have swift mailer too.

Again, this is on your requirement. If you don't need to send hundreds of notifications that are time sensitive, you don't need these tools then.

Upvotes: 0

Related Questions