Requirements for sending e-mails from PHP

Description:

We need to send e-mails directly from a PHP script.

Solution:

First, in php.ini the smtp port should be set to 25, but this is usually by default. To locate your php.ini file in the server configuration you can use in the PHP script the command:

echo php_ini_loaded_file ();

Next, make sure the sendmail package is installed on your server. For nginx use:

apt-get install sendmail

In case of missing packages like sendmail-bin, install that first:

apt-get install sendmail-bin

Now you should be able to send email directly from PHP with your own server installation:

mail($mailTo, $mailSubject, $mailMessage, $mailHeaders, $mailAttachments);

For WordPress installations, you can use wp_mail() with same parameters and functionality. There are also some plugins out there, but they don’t make sense in using unless you need extra security or such.

Advertisements

About admin

Just another php developer trying to give something back to the community.
This entry was posted in Linux, PhP, Wordpress and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s