【问题标题】:How to make PHP Mail() function use a specific SMTP server?如何使 PHP Mail() 函数使用特定的 SMTP 服务器?
【发布时间】: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 发送电子邮件的帐户的用户编写一个自动邮件程序。

【问题讨论】:

    标签: php email


    【解决方案1】:

    mail() 不支持 smtp。您需要使用支持 smtp 的邮件框架,例如:http://pear.php.net/package/Mail

    见:smtp configuration for php mail

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 2012-08-24
      • 1970-01-01
      • 2020-05-15
      • 2012-01-09
      • 2013-03-21
      相关资源
      最近更新 更多