您的位置:首页 > 编程语言 > PHP开发

ubuntu下,使用postfix实现php发送mail功能

2011-09-08 16:46 609 查看
1、ubuntu 下安装postfix,执行命令:

# apt-get install postfix popa3d

如果不需要pop3服务,把popa3d去掉

2、在php.ini配置文件上,设置mail函数:

1)打开php.ini配置,下面是我的php.ini路径:

# vi /home/service/web/config/php/lib/php.ini

2)找到:sendmail_path ,将其设置为:

sendmail_path = /usr/sbin/sendmail -t

注意:这里需要先到/usr/sbin/ 目录中,确认是否存在sendmail文件。

3、启动postfix:

# /etc/init.d/postfix start

4、重启apache:

# /etc/init.d/apache2 restart

5、以上完成。你可以写一个发送email的php文件做测试,如下:

<?php

$send = mail('yourEmail@test.com', 'My Subject', 'The test mail');

if($send){

echo 'true';

}else{

echo 'false';

}

?>

以上,运行如果显示true,则,你将会在'yourEmail@test.com'中收到一封主题为'My Subject'的email。

 

如果要限制外来主机访问smtp服务,修改/etc/postfix/main.cf里的

inet_interfaces=all



inet_interfaces=localhost
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息