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

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文件做测试,如下:

$send = mail('[email protected]', 'My Subject', 'The test mail');
if($send){
echo 'true';
}else{
echo 'false';
}
?>
以上,运行如果显示true,则,你将会在'[email protected]'中收到一封主题为'My Subject'的email。

 

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

inet_interfaces=all

inet_interfaces=localhost

你可能感兴趣的:(Ubuntu,ubuntu,php,email,path,apache,测试)