在php里从本地经过msmtp发送邮件
参看http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmail-account-on-linux/?的步骤:
?
?
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 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 ( [email protected]', 'Test mail from localhost', 'Working Fine.' ) );echo 'Mail sent';elseecho 'Error. Please check error log.';
Replace the [email protected] 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
显然要保证有/etc/msmtprc文件并要设置好它的配置内容。我的/etc/msmtprc内容如下:# Set default values for all following accounts.
defaults
logfile /usr/local/msmtp/msmtp.log
# The SMTP server of the provider.
account test
# SMTP邮件服务器地址
host smtp.ym.163.com
# 发送的邮件Email
from [email protected]
auth login
# 邮件服务器登录账号
user [email protected]
# 邮件服务器登陆密码
password 12345678
# Set a default account
account default : test
不过,我打开上面的测试php时,开始时出来Error. Please check error log.
发送邮件不成功,查看apache的error_log, 找到错误信息:
msmtp: /etc/msmtprc: must be owned by you
原来是/etc/msmtprc的权限是777的话也不行,需要限制。 ps aux|grep httpd查看apache的进程的用户名是www,
然后:
chown www.www /etc/msmtprc
chmod 600 /etc/msmtprc # 一定要600而不是777 !
搞定!然后在mantis里配置?$g_phpMailer_method ? ? ? ? ? ? = PHPMAILER_METHOD_MAIL这样比配置 PHPMAILER_METHOD_SMTP 发邮件要快得多,都可立即收到邮件!?
?
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
- Restart apache:
上一篇: 一道考CSS的题目,求解(最好能说清为什么)_html/css_WEB-ITnose
下一篇: Codeforces Round #283 (Div. 2)-C. Removing Columns_html/css_WEB-ITnose
推荐阅读
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论