【问题标题】:Php mailer google smtp working on localhost not working on live sitePhp mailer google smtp 在本地主机上工作 不在现场工作
【发布时间】:2013-06-13 05:26:40
【问题描述】:

我正在尝试在注册后向注册用户发送邮件。

为此,我正在使用 phpmailer 库。

我的代码如下:

function smtpmailer($to, $from, $from_name, $subject, $body) {
    global $error;
    $username = "xyz@demo.net";
    $password = "1234567";
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465;
    $mail->Username = $username;
    $mail->Password = $password;
    $mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
    $mail->CharSet = 'UTF-8';
    $mail->Encoding = '8bit';
    $mail->ContentType = 'text/html; charset=utf-8\r\n';
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    $mail->IsHTML(true);
    $mail->WordWrap    = 900; 
    if (!$mail->Send()) {
        $error = 'Mail error: ' . $mail->ErrorInfo;
        return false;
    } else {
        $error = 'Message sent!';
        $mail->SmtpClose();
        return true;

    }

此代码在 localhost 上运行良好,但我将其上传到 mysite 然后它显示以下错误: SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed.

我的网站托管在文件夹中,例如 (myhost.in/mysite)。

请帮我找出问题并解决它

在此先感谢...

【问题讨论】:

  • 看起来是服务器问题。他们有防火墙吗?

标签: php smtp gmail phpmailer


【解决方案1】:

我遇到了一些托管服务提供商不支持外部邮件主机的问题。您必须询问您的托管支持天气他们是否允许外部主机。

我使用了托管服务提供商的 imap 设置,现在已解决 希望这会对某人有所帮助!

【讨论】:

    【解决方案2】:

    转到链接 - https://accounts.google.com/b/0/DisplayUnlockCaptcha 然后点击允许访问按钮 原因:出于安全原因,谷歌不允许任何程序在用户的空调中自动登录。

    【讨论】:

    • 帮助很大。轻松解决我的问题。
    【解决方案3】:

    https://support.google.com/mail/answer/78754

    您可能需要开启“访问安全性较低的应用程序”设置 https://www.google.com/settings/security/lesssecureapps 帮了我

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 2020-11-03
      • 1970-01-01
      • 2018-10-27
      • 2016-08-04
      • 2014-01-15
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多