【问题标题】:phpmailer working on localhost but when i upload it on my ubuntu server it gives me error and mail is not sending(I am using gmail smtp)phpmailer 在本地主机上工作,但是当我将它上传到我的 ubuntu 服务器上时,它给了我错误并且邮件没有发送(我使用的是 gmail smtp)
【发布时间】:2020-09-23 20:38:42
【问题描述】:
    <?php 
    if(isset($_POST['sendmail'])) {
        
        require 'PHPMailerAutoload.php';
        require 'credential.php';

        $mail = new PHPMailer;

        $mail->SMTPDebug = 4;                               // Enable verbose debug output

        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = EMAIL;                 // SMTP username
        $mail->Password = PASS;                           // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                                    // TCP port to connect to

        $mail->setFrom(EMAIL, 'litdeveloper');
        $mail->addAddress($_POST['email']);     // Add a recipient

        $mail->addReplyTo(EMAIL);
        // print_r($_FILES['file']); exit;
        for ($i=0; $i < count($_FILES['file']['tmp_name']) ; $i++) { 
            $mail->addAttachment($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]);    // Optional name
        }
        $mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = $_POST['subject'];
        $mail->Body    = '<div style="border:2px solid red;">This is the HTML message body <b>in bold!</b></div>'.$_POST['message'];
        $mail->AltBody = $_POST['message'];

        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message has been sent';
        }
    }
 ?>

如何解决这个错误,我在评论此 $mail->isSMTP() 后也尝试过,但它不起作用。 它在 XAMP 上正常工作 电子邮件 ID 和密码是正确的我应该怎么做请帮助我

【问题讨论】:

标签: php amazon-ec2 phpmailer ubuntu-18.04


【解决方案1】:

当您收到错误消息时,最重要的事情是阅读它所说的内容,所以当它说:

534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 g206sm18050557pfb.178 - gsmtp

解决此问题的方法是使用普通网络浏览器登录您的 gmail 帐户,如果您想了解他们为什么要求您这样做,请点击该链接,这不足为奇。

有关其他信息,您应该点击调试输出中出现的故障排除指南的链接(您在此处转发了两次!),特别是 this part,它解决了您遇到的确切问题。

除了您使用的是非常旧版本的 PHPMailer 之外,您的配置和代码看起来是正确的;这不是问题所在。

顺便说一句,您现在应该更改您的 gmail 密码,因为它在调试输出中以易于解码的格式显示。

【讨论】:

  • 我从浏览器中注销所有 gmail 帐户并再次登录并转到此链接(“accounts.google.com/b/0/DisplayUnlockCaptcha”),然后按继续,然后我再次在浏览器中重新加载我的代码,最后它可以工作了。 .非常感谢先生/.你给了我一个解决这个问题的方法,它对我很有帮助,非常感谢
猜你喜欢
  • 1970-01-01
  • 2014-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多