tags:

views:

2641

answers:

6

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.

  1. Since mail() doesn't take SMTP info, does it just automatically use GoDaddy's (or whatever hosting you may be on)?

  2. 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?

+4  A: 

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

Silfverstrom
can I just specify ANY server? for example...can I send through gmail's server, but retain my domain name in my email? that probably seems like a dumb quesiton, but im vague in this area
johnnietheblack
@johnnietheblack: If you can access the php.ini file (i.e. PHP's settings), you can set the SMTP server to whatever you want. (this is definitely not the case on any sort of shared hosting)
Piskvor
+2  A: 

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

Chris S
so does that mean if i host at GoDaddy that I can't point my mail() script to a different authenticated SMTP on a hosting services that doesn't care about how many i send without using PEAR? thanks for your patience:)
johnnietheblack
The mail() function is very basic and doesn't support sending a username/password key pairing to SMTP hosts that require authentication. You have to write a bunch of custom code to get the mail() function to work with it, which is why I suggested a package =PHope that helps.
Chris S
+1  A: 

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.

Kev
ill check that out, thanks:) does it work well for bulk mailing? better than PEAR?
johnnietheblack
Couldn't make any comparisons to the PEAR mail package unfortunately. Seems to work fine with bulk mailers, got a couple of customers using it.
Kev
+1  A: 

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.

Darryl Hein
+1  A: 

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.

Matt C
A: 

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.

DC Coder