First of all, follow this tutorial:
Install msmtp on your linux box and configure it to work with Gmail.
Msmtp is highly configurable and you can easily configure it to work with any smtp server. If you wish to use any other service with msmtp, you may read its manual and configure it.
Proceed to next step only if you have successfully configured and are able to send a test message.
Open php.ini in your text editor. sudo gedit /etc/php5/apache2/php.ini
Search for ‘sendmail_path’ and change it to look like
sendmail_path = '/usr/bin/msmtp -t'
Save the file and exit the text editor.
Please note that your msmtp path may vary if you are not using Ubuntu. You may find the path to executable by:
which msmtp
Restart apache:
sudo/etc/init.d/apache2 restart
OR
sudo/opt/lampp/lampp restart
Everything’s done. Lets test if the mail() function is working now:
if ( mail ( 'yourusername@gmail.com', 'Test mail from localhost', 'Working Fine.' ) );
echo 'Mail sent';
else
echo 'Error. Please check error log.';
Replace the yourusername@gmail.com with your own username, save it into a php file along with php delimeters in your virtual host root folder and execute it through the browser. You should receive a mail.
跟上述步骤大同小异。
msmtp在ubuntu下apt-get install msmtp就可以安装, 安装完后, msmtp --ver 查看:
......
System configuration file name: /etc/msmtprc
User configuration file name: /root/.msmtprc