【问题标题】:Hostgator send mail [duplicate]Hostgator发送邮件[重复]
【发布时间】:2020-12-27 11:26:59
【问题描述】:

我正在使用以下代码从我的网站发送电子邮件:

<?php

$to = "mygmail@gmail.com;
$subject = "My Site - NoReply";
$headers = "From: do not reply @ My Site" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "You have received a message from the My site: <br /><br />";
$message .= "Greetings <strong>My Name</strong>, <br /><br />";
$message .= "You have been granted access to the My site.<br /><br />";
                    
mail($to, $subject, $message, $headers);

?>

我的网站由 Hostgator 托管。他们建议我应该为 SMTP 使用端口 465。

我刚和他们聊完。万事俱备,他们无能为力。

话虽如此,为什么我无法使用上述方式发送电子邮件?

我在我的工作中使用了相同的代码,它使用 Apache 服务器,并且我从网站发送任何电子邮件都没有问题。

我缺少什么来完成这项工作?

【问题讨论】:

标签: php email smtp phpmailer


【解决方案1】:

这里最明显的问题是您没有使用 SMTP

PHP 的 mail() 函数通过 shell 向 sendmail 二进制文件提交消息,根本不直接使用网络,因此您无法按照他们的要求进行操作。

通过 SMTP 发送,甚至发送到 localhost,比使用 mail() 更可取,因为它更快、更安全、更可靠。

你用PHPMailer 标记了这个问题,可以直接通过 SMTP 发送,@j4g0 提供了一个合理实现的链接。在 SO 和 PHPMailer 项目中还有更多示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 2015-07-28
    • 2016-05-10
    • 2020-03-25
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多