简体   繁体   English

phpmailer 在本地主机上工作,但是当我将它上传到我的 ubuntu 服务器时,它给了我错误并且邮件没有发送(我使用的是 gmail smtp)

[英]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)

    <?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';
        }
    }
 ?>

How can I resolve this error i also tried after commenting this $mail->isSMTP() but it is not working.如何解决此错误,我在评论此 $mail->isSMTP() 后也尝试过,但它不起作用。 It is working properly on XAMP Email id and password is correct what should i do plz help me out它在 XAMP 电子邮件 ID 上正常工作,密码正确,我该怎么办,请帮帮我

The most important thing to do when you have an error message is read what it says , so when it says:当您收到错误消息时,最重要的事情是阅读它所说的内容,因此当它说:

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

It should not come as a surprise that the way to fix this is to log in to your gmail account using a normal web browser, and follow that link if you want to find out why they ask you to do this.解决此问题的方法是使用普通网络浏览器登录您的 Gmail 帐户,如果您想了解他们要求您这样做的原因,请点击该链接,这不足为奇。

For other information, you should follow the link to the troubleshooting guide that appears in your debug output (and you reposted here twice!), in particular this part , which addresses the exact problem you have.有关其他信息,您应该点击调试输出中出现的故障排除指南的链接(并且您在此处重新发布了两次!),特别是这部分,它解决了您遇到的确切问题。

Apart from the fact that you're using a very old version of PHPMailer, your config and code looks correct;除了您使用的是非常旧版本的 PHPMailer 之外,您的配置和代码看起来是正确的; that's not where the problem lies.这不是问题所在。

Incidentally, you should now change your gmail password as it is displayed in an easily decoded format in your debug output.顺便说一句,您现在应该更改您的 gmail 密码,因为它在调试输出中以易于解码的格式显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Gmail smtp服务器发送邮件时,PHPMailer给出错误 - PHPMailer gives an error when sending mails with the Gmail smtp server 我正在使用 PHPMailer,但在 gmail 中未收到邮件 - I am using PHPMailer but mail not received in gmail 我如何通过php smtp服务器使用phpmailer发送邮件 - how can i send mail using phpmailer thru gmail smtp server 如何使用PHPMailer和localhost SMTP将邮件发送到gmail? - How to send mail using PHPMailer with localhost SMTP to gmail? PHPMailer错误使用smtp.gmail.com发送邮件 - PHPMailer error sending mail with smtp.gmail.com PHPmailer 不使用 gmail 的 SMTP 从本地主机发送电子邮件 - PHPmailer not sending emails from localhost using gmail's SMTP 我正在我的本地主机上使用 Mailgun 编写教程。 发送给我一个错误 - I am working on a tutorial with Mailgun in my localhost. Send gives me an error 在本地主机上使用 PHPMailer SMTP 发送邮件失败 - Sending mail with PHPMailer SMTP on localhost fails to send 为什么我不能在我的托管域中使用 swiftmailer 发送邮件,但是从我的本地主机服务器发送邮件时没有错误 - Why can I not send mail with swiftmailer in my hosted domain but there is no error when sending it from my localhost server 在服务器中通过gmail smtp发送邮件时出现问题,但在localhost中工作正常 - problem in sending mail by gmail smtp in server but works fine in localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM