PHPMailer works on localhost, but fails on server

[亡魂溺海] 提交于 2019-12-12 04:09:12

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/21942933/phpmailer-works-on-localhost-but-fails-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!