Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What SMTP server does PHP mail() use by default, and are there better options?

Tags:

php

email

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?

like image 347
johnnietheblack Avatar asked Jun 10 '09 19:06

johnnietheblack


People also ask

What is the default SMTP port value set for PHP mail?

Used under Windows only: host name or IP address of the SMTP server PHP should use for mail sent with the mail() function. Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25.

Does PHP mail need SMTP?

PHP mail() does not usually allow you to use the external SMTP server and it does not support SMTP authentication. Here's what you can do with PHP's built-in mail function(): create simple HTML/text messages without attachments and images. send emails via localhost and Xmapp.

What does PHP mail use?

PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail. On a hosted server, the SMTP settings would have already been set. The SMTP mail settings can be configured from “php. ini” file in the PHP installation folder.

Where does PHP mail send from?

PHP's built-in mail() function is one of the simplest ways to send emails directly from the web server itself. It just takes three mandatory parameters: the email address, email subject and message body—and sends it to the recipient.


2 Answers

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.

like image 122
Darryl Hein Avatar answered Oct 05 '22 22:10

Darryl Hein


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:

  1. https://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.smtp.php?r=170
  2. http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
like image 33
Suresh Kamrushi Avatar answered Oct 06 '22 00:10

Suresh Kamrushi