【发布时间】:2015-08-03 01:28:30
【问题描述】:
如何让 php 的邮件功能从特定的单独 SMTP 服务器发送电子邮件,而不是使用本地主机?
我的代码:
<?php
$to = "user@AOL.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <noreply@foo.com>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
背景信息: 我目前有一个运行 Apache 的 Linux 服务器,还充当邮件服务器 (foo.com) 和运行 LAMP 堆栈的单独服务器 (bar.com)。
在 bar.com 上,我正在尝试为注册从 foo.com 发送电子邮件的帐户的用户编写一个自动邮件程序。
【问题讨论】: