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

PHP makes it easy to send email from web applications

Messaging
Lasse Kristensen / Getty Images

PHP makes it easy to send mail from Web applications, but it needs a bit of configuration in php.ini to use a remote SMTP server.

The relevant section in php.ini 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 is the same address that you use in your email program for the outgoing mail server, "smtp.isp.net," for example. The other setting is sendmail_from, which specifies the default email address PHP emails are sent from.

Configure PHP to Use a Remote SMTP Server for Sending Mail

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 looks like this:

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