为什么php从本地主机发送电子邮件,而不是使用PHPMailer从服务器发送电子邮件? [英] Why php is sending email from localhost not from server using PHPMailer?

查看:85
本文介绍了为什么php从本地主机发送电子邮件,而不是使用PHPMailer从服务器发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将PHPMailer与SMTP一起使用来发送电子邮件.首先,我只是从本地主机对其进行测试,并且已成功发送了电子邮件.

I am using PHPMailer with SMTP to send email. 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;

错误消息是:

2016-04-22 05:53:10 SMTP错误:无法连接到服务器:连接被拒绝(111)2016-04-22 05:53:10 SMTP connect()失败. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 邮件未发送

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. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting mail is not send

我不明白为什么它向我显示此错误消息,因为我使用的是100%相同的代码.

I do not understand why it's showing me this error message becuase I am using 100% same code.

这是我使用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';
}

推荐答案

某些服务器具有某些功能,这些功能使用户无法自行启用.请与您的托管服务提供商联系,以查看他们是否启用了mail()功能.

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.

在这种情况下,smtp邮件功能可以完美地在localhost中运行,但不能在服务器中运行. 这样您就可以更改服务器设置

In this case smtp mail function perfectly working in localhost but not in server.. soo you change the server setting

这篇关于为什么php从本地主机发送电子邮件,而不是使用PHPMailer从服务器发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆