PHP Mail Configuration

The php.ini File

The php.ini file is where you configure your PHP installation. This is the file you need to edit in order to configure PHP to send mail.

You need to ensure that the php.ini file contains details of the mail server that should be used whenever your application sends mail.

To check/change your PHP mail configuration:

  1. Open your php.ini file (if you don’t know where this is, see below)
  2. Search for the line that reads [mail function]
  3. Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP.
  4. Save/close the php.ini file
  5. Restart your web server

Here’s an example of what the mail settings could look like when you first open the php.ini file:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25; For Win32 only.
;sendmail_from =

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
;sendmail_path =

If you’re using a UNIX based system, you will need to change the line that reads ;sendmail_path =. You will also need to remove the semicolon from the start of this line (semicolons indicate that the line is a comment). For example, sendmail_path = /usr/sbin/sendmail.

If you’re using a Windows system, you should change the line that reads SMTP = localhost to include your mail server (or your ISP’s mail server). You could leave it at localhost if you’re using your own local SMTP server. If you aren’t using your own local SMTP server, you will need to enter a mail server that you have access to (such as your ISP’s mail server). For example, SMTP =

You should also set a default “From” email address by changing the line that reads ;sendmail_from = For example, sendmail_from =

Don’t Know Your php.ini Location or sendmail_path Path?

If you don’t know where your php.ini is, or what your sendmail_path setting should be, read on…

Your php.ini may be located here: /private/etc/php.ini. And there’s a chance that your sendmail path will be at /usr/sbin/sendmail). Having said this, each PHP installation is different, so you should check using phpinfo().

Fortunately, this is easy to do.

phpinfo() is used to view your PHP configuration details. You can do this by creating a .php file with the following line on it: <?php phpinfo(); ?>. When you run this in your browser, you will see a full list of PHP configuration variables. Simply search for the lines that contain php.ini and sendmail_path to see the values you need to use.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s