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 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题