简体   繁体   English

为什么php从本地主机发送电子邮件而不是使用PHPMailer从服务器发送?

[英]Why php is sending email from localhost not from server using PHPMailer?

I am using PHPMailer with SMTP to send email.我正在使用 PHPMailer 和 SMTP 发送电子邮件。 First I just test it from my localhost and it's successfully sent email.首先,我只是从我的本地主机上测试它,它已成功发送电子邮件。

But when I upload the same code to my service it's showing me following error without sending email;但是当我将相同的代码上传到我的服务时,它会显示以下错误而不发送电子邮件;

Error Message is :错误信息是:

2016-04-22 05:53:10 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-22 05:53:10 SMTP connect() failed. 2016-04-22 05:53:10 SMTP 错误:无法连接到服务器:连接被拒绝 (111) 2016-04-22 05:53:10 SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting mail is not send https://github.com/PHPMailer/PHPMailer/wiki/疑难解答邮件未发送

I do not understand why it's showing me this error message becuase I am using 100% same code.我不明白为什么它会向我显示此错误消息,因为我使用的是 100% 相同的代码。

Here is my email sending script using PHPMailer :这是我使用 PHPMailer 发送电子邮件的脚本:

require 'PHPMailerAutoload.php';
$m =  new PHPMailer();

$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;

$m->Host = 'smtp.gmail.com';
$m->Username = 'username';
$m->Password = 'password'; // google app password
$m->SMTPSecure =  'ssl';
$m->Port = 465;

$m->From = 'from@gmail.com';
$m->FromName = 'Shibbir Ahmed';
$m->addReplyTo('reply@gmail.com', 'Reply Address');
$m->addAddress('to@gmail.com', 'Shibbir Ahmed');

$m->Subject = 'Here is an email';
$m->Body = 'This is email';
$m->AltBody = 'Alt body';
if($m->send()) {
    echo 'mail send';
} else {
    echo 'mail is not send';
}

Some servers have certain functions disable that a user cannot enable them selves.某些服务器具有某些功能禁用,用户无法自行启用。 Check with your hosting provider to see if they have the mail() function enabled.请咨询您的托管服务提供商,看看他们是否启用了 mail() 功能。

In this case smtp mail function perfectly working in localhost but not in server.. soo you change the server setting在这种情况下,smtp 邮件功能在 localhost 中完美运行,但在服务器中却没有。所以你改变了服务器设置

That link to the troubleshooting guide is there for a reason - if you follow it it will tell you exactly what is wrong: GoDaddy blocks outbound SMTP, so you have to use their mail servers.存在故障排除指南的链接是有原因的 - 如果您遵循它,它会告诉您究竟出了什么问题:GoDaddy 阻止出站 SMTP,因此您必须使用他们的邮件服务器。 There are many duplicates of this question, so search before you post .这个问题有很多重复,所以在你发帖之前先搜索一下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM