PHPMailer在localhost上工作,但在服务器上失败 [英] PHPMailer works on localhost, but fails on server
问题描述
我的脚本在WAMP上的本地主机上运行完美,但是当我尝试在我的服务器上运行它时失败,我试图在另一台服务器上运行它,并向我发送相同的错误。
这是我在服务器上运行脚本时得到的错误:
> SMTP错误:无法连接到服务器:连接超时(110)
> SMTP连接()失败。
这是我的PHPMailer配置:
require('PHPMailer-master / PHPMailerAutoload.php');
$ alertvalue = $ _GET [alert];
$ mail = new PHPMailer();
回显< p>实例已创建。< / p>;
$ mail - > isSMTP();
$ mail - > Host =ssl://smtp.gmail.com; //我也尝试过使用ssl://
$ mail - >端口= 465; //我也试过587和25
$ mail - > SMTPAuth = true;
$ mail - >用户名='-------------@gmail.com';
$ mail - >密码='-------------';
$ mail - > SMTPSecure ='tls'; //我也试过用ssl
$ mail - > SMTPDebug = 1;
$ mail - > From ='--------------@gmail.com';
$ mail - > FromName ='----------';
$ mail - > addAddress('-------------- @ gmail.com','----');
任何想法为什么会发生?我已经看过几个类似的情况,但我还没有找到我的问题。
只需评论$ mail-> IsSMTP(); ..我有同样的问题..本地主机上它的工作和活服务器不工作..后我评论$ mail-> IsSMTP();这,它的工作正常..希望可能对你有帮助它是
My script runs perfect on my localhost on WAMP, but when I try to run it on my server it fails, I tried also to run it on another server and it sends me the same error. This is the error I get when running the script on the server:
> SMTP ERROR: Failed to connect to server: Connection timed out (110)
> SMTP connect() failed.
This is my PHPMailer configuration:
require ('PHPMailer-master/PHPMailerAutoload.php');
$alertvalue = $_GET["alert"];
$mail = new PHPMailer();
echo "<p> Instance created. </p>";
$mail -> isSMTP();
$mail -> Host = "ssl://smtp.gmail.com"; // I've also tried withou the ssl://
$mail -> Port = 465; // I've also tried 587 and 25
$mail -> SMTPAuth = true;
$mail -> Username = '-------------@gmail.com';
$mail -> Password = '-------------';
$mail -> SMTPSecure = 'tls'; // I've also tried with ssl
$mail -> SMTPDebug = 1;
$mail -> From = '--------------@gmail.com';
$mail -> FromName = '----------';
$mail -> addAddress('--------------@gmail.com', '----');
Any idea why this is happenning? I've looked at several posts with a similar situation but I haven't been able to figure out my problem yet.
Just comment $mail->IsSMTP(); ..I had same problem..On localhost its working and live server not working..After I commented $mail->IsSMTP(); this, Its working fine..Hopes so might be helpful for u it is
这篇关于PHPMailer在localhost上工作,但在服务器上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!