5 Reasons to avoid mail() in PHP scripts
Jon Moffet
Here are my 5 reasons why I do not prefer to use mail() function to send emails from my PHP scripts :
- Depends too much on your (shared hosting) web server to send email
- Not flexible - you can't choose which SMTP server to use to send your mails
- Not portable - Windows testing server may have problem with mail() code
- Vulnerable - mail() code is notoriously known for its vulnerability to Email Injection attacks
- Hard to use/Cryptic - although seems simple, mail() is hard to use. You have to be very careful
in structuring your mail headers to send emails to multiple senders or sending html emails (or attachment)
Another compelling reason is :
Risk being marked as Spam
Your emails risked of being marked as SPAM in shared hosting environment, this is because your email is sent from the same server that (probably) hosted site that send spam emails.
RBL Anti-Spam services might mark your email as spam and it will end up in bulk-email folder in your favorite email clients.
So the best solution is to use PHPMailer class which enables you to send email through your own private SMTP server and disassociate yourself from all those spammers.
Please avoid mail() as it encourage email spams.
ps: I do not deny the effectiveness of mail() if it is coded properly. However, most people tends to use mail() blindly without proper checkups and input validation which can lead to email injection attacks and other abuses.
Tags: spams, email, smtp, mail, php, phpcode, contact form, scripts
Posted in Uncategorized |







