In php, send emails locally via msmtp. refer to the http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmai. in php, send emails locally via msmtp.
See the http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmail-account-on-linux? Steps:
?
?
Step by step instructions:
?
- First of all, follow this tutorial:
Install msmtp on your linux box and configure it to work with Gmail.
?
Msmtp is highly writable able and you can easily configure it to work with any smtp server. If you want 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:
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';elseecho '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 showould receive a mail.
Similar to the above steps.
Msmtp can be installed in apt-get install msmtp in ubuntu. after the installation, check msmtp -- ver:
......
?
System configuration file name:/etc/msmtprc
User configuration file name:/root/. msmtprc
Obviously, you must ensure that the/etc/msmtprc file is available and set its configuration content. My/etc/msmtprc content is as follows: # Set default values for all following accounts. defaults
Logfile/usr/local/msmtp. log # The SMTP server of the provider. account test
# SMTP mail server address host smtp.ym.163.com
# Send the email Emailfrom yanghf@kopere.comauth login
# Mail server login account user yanghf@xxx.com # mail server login password 12345678 # Set a default accountaccount default: test
However, when I open the test php above, an Error occurs at the beginning. please check error log. failed to send the email. check apache's error_log and find the error message: msmtp:/etc/msmtprc: must be owned by you.
It turns out that the permission of/etc/msmtprc is 777, but it does not work and requires restrictions. Ps aux | grep httpd: check that the username of the apache process is www. Then: chown www. www/etc/msmtprc chmod 600/etc/msmtprc #600 instead of 777! Done! Then configure in mantis? $ G_phpMailer_method? ? ? ? ? ? = PHPMAILER_METHOD_MAIL is much faster than configuring PHPMAILER_METHOD_SMTP to send emails. you can receive emails immediately!
?
?