Reputation: 13340
I host my site with GoDaddy , and I use the PHP mail()
function at the moment to send form mails from my site. GoDaddy has a 1000 SMTP relay limit per day for form mail stuff, but they swear that with my PHP script that I should not be touching it.
Since mail()
doesn't take SMTP info, does it just automatically use GoDaddy's (or whatever hosting you may be on)?
If my site is going to be expecting more than 1000 emails sent out a day (separate instances, not in a loop), should I be using a different method, or is mail()
the right choice?
Upvotes: 14
Views: 42509
Reputation: 16086
Dont use mail() function of php it will send your mail to junk only. Instead use SMTP php mailer function.
Why we should use SMTP instead PHP mail():
SMTP log in to an actual account on a mailserver and send the mail through SMTP to another mail server. If the mail server is configured correctly, your mails are sent from an actual account on a mailserver and will not wind up flagged as spam.
Mail sent with the mail() function is sent with sendmail in most cases. There is no authentication going on and it will almost always be flagged as spam if you use the "From:" in the extra headers.
This is because if you take a look at an original email file in say, gmail, you will see the headers that are sent. You are actually sending from [email protected] and not [email protected] like you had told the mail function to do. If you use SMTP and view the original the email is actually sent from [email protected]
You can download SMTP class from:
Upvotes: 11
Reputation: 2530
Since this is an old post I thought it would be helpful if I updated the answer -
This is a lot simpler to do now than it used to be :-) In PHP 4 the PEAR Mail package is typically already installed, and this really simple tutorial shows you the few lines of code that you need to add to your php file http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
Most hosting companies list the SMTP settings that you'll need. I use JustHost, and they list theirs at https://my.justhost.com/cgi/help/26 (under Outgoing Mail Server)
Upvotes: 2
Reputation: 16044
I've been using the open source project phpmailer for about seven years-- it is terrific! You could use it to connect to an offsite SMTP server.
Upvotes: 2
Reputation: 43
mail() does use the setting as defined in the php.ini. Windows servers require an actual smtp server while *nix servers will use whatever mta is installed on the server (if any).
As others have mentioned, if you do want to use an alternate smtp server, use an alternative library like SwiftMailer. Also you'd want to make sure the smtp server is fast. I have seen slowdowns when using an smtp server like gmail.
GoDaddy uses a Smart SMTP Relay, even on for dedicated servers hosted with GoDaddy. The limit is based on how many emails are going through the Smart relay.
If you have a valid reason for needing to send more emails and you can verify that your site isn't spamming and that all of the emails are opt-in, support will increase the limit for you if you give them an estimate of how many emails you need to send out.
Upvotes: 3
Reputation: 145097
On a *nix machine, the PHP mail()
function does not support SMTP, but instead uses the sendmail() or other configured mail script on the server. This script can send through an SMTP, but this isn't the easiest way within PHP (unless you already have the script). To use SMTP, I would recommend PHPMailer. I have been using it for a few years now and have been impressed. It supports SMTP along with many other protocols and also has other helpful functionality, such as adding a text only body for an HTML email and creating the proper email headers. You can also extend the class to set defaults, such as the SMTP server and from email/name so you don't have to set these every time you want to send an email. It also does very nice error reporting and debugging.
I would also recommend this class for sending out 1000s of emails. I recently did >5000 in one day with it and had no problems.
Upvotes: 7
Reputation: 119826
If you need to use a third party mail service I'd recommend dropping the use of mail()
and replace with the SwiftMailer library. It's a feature rich component (supports authentication, attachments, encryption etc) we've used it in a few places. It's also free and open source.
Upvotes: 1
Reputation: 86
If you need to use an external email server that requires authentication, you will not be able to use the PHP mail() function.
I recommend using: http://pear.php.net/package/Mail
Upvotes: 4
Reputation: 29330
Php uses by default, the local mail-server. However you can specify this in your php.ini configuration file.
If you expect to send more email than that, you might want to look into finding a different server to mail from, or alternative hosting
Upvotes: 13