How to Configure PHP to Use a Remote SMTP Server for Sending Mail

Man using laptop on sofa - Sam Edwards/Caiaimage/Getty Images
Sam Edwards/Caiaimage/Getty Images
Updated December 16, 2014.

PHP makes it easy to send mail from Web applications. But it still needs a bit of configuration. As you probably know, PHP configuration happens php.ini.

The relevant section for email configuration is [mail function], and to make PHP use an external mail server you must set SMTP to your ISP's mail server's address. This will be the same address that you use in your email program for the outgoing mail server, "smtp.isp.net", for example.

The other setting sendmial_from, which specifies the default email address PHP emails are sent from.

Configure PHP to Use a Remote SMTP Server for Sending Mail

Note that setting up the internal mail function to use SMTP is only available on Windows. On other platforms, PHP should use the locally available sendmail or sendmail drop-in just fine.

Alternatively, you can use the PEAR Mail Package.

A typical configuration might look like:

[mail function]
SMTP = smtp.isp.net
sendmail_from = me@isp.net

This site uses cookies. Our Privacy Policy has details and opt-out info.