duanmianzhou5353 2015-05-21 11:42
浏览 133
已采纳

如何使PHP Mail()函数使用特定的SMTP服务器?

How do you make php's mail function send email from a specific separate SMTP server instead of using the local host?

My code:

<?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" . "
";
$headers .= "Content-type:text/html;charset=UTF-8" . "
";


$headers .= 'From: <noreply@foo.com>' . "
";

mail($to,$subject,$message,$headers);
?>

Background info: I currently have a Linux server running Apache and also acting as a mail server (foo.com) and a separate server (bar.com) running a LAMP stack.

On bar.com I am trying to code a auto mailer for users registering accounts that sends the emails from foo.com.

  • 写回答

2条回答 默认 最新

  • duanmi8349 2015-05-21 12:06
    关注

    For the solution to your problem you have to use PHPMailer and include file like this:

    require_once ('class.phpmailer.php');
    

    Download the code of PHPMailer from the net and place it in your folder and give correct path.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog