简体   繁体   English

phpgmailer突然停止工作

[英]phpgmailer stopped working suddenly

I used phpgmailer to send emails and it was working smoothly. 我使用phpgmailer发送电子邮件,并且运行正常。 Today I tested my project and it's not working now. 今天我测试了我的项目,但现在无法正常工作。

   <?php                  
    require_once('class.phpgmailer.php');
    $mail = new PHPGMailer();
    $mail->Username = 'username@gmail.com';
    $mail->Password = '********';
    $mail->From = 'username@gmail.com';
    $mail->FromName = "<blah>";
    $mail->Subject = 'something';
    $mail->AddAddress('xyz@gmail.com');


    $mail->Body =  "Hello Sir"."\n"."     
    Your Password is : ."."";
    $mail->Host = 'smtp.gmail.com'; 
    $mail->Port = 465;
    $mail->Send();

    if(!$mail->Send())
            {

       echo 'Message could not be sent.' ;
       echo 'Mailer Error: ' . $mail->ErrorInfo;

       exit;
            }
       echo 'Message has been sent';

I suggest you download PHPMailer and try this code: 我建议您下载PHPMailer并尝试以下代码:

    require("phpmailer/class.phpmailer.php");

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->Host     = "ssl://smtp.gmail.com";
    $mail->Port     = 465;
    $mail->Username = "from@gmail.com";
    $mail->Password = "****";
    $mail->FromName = "Sender name";
    $mail->Subject  = "test";
    $mail->Body     = "Test body";
    $mail->AddAddress('sender@mail.com');
    if(!$mail->Send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }else{
        echo "Message has been sent";
    }

@goose is right, remove the first $mail->Send() and leave the one in the if statement. @goose是正确的,删除​​第一个$mail->Send()并将其保留在if语句中。 If the From address is the same as the username email, then you don't need that either as it will take it from your gmail account. 如果From地址与用户名电子邮件相同,则您也不需要该地址,因为它将从您的gmail帐户中获取。

Try that and see if it works. 尝试一下,看看是否可行。

EDIT: try adding the following; 编辑:尝试添加以下内容;

    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // 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 = 'email@gmail.com';  
    $mail->Password = 'password';     

Try that and if there are errors, then it should give you more detail. 尝试这样做,如果有错误,则应该为您提供更多详细信息。

EDIT2: If that doesn't work then I suggest trying PHPMailer instead of PHPGmailer - and follow the tutorial here: http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/ EDIT2:如果那不起作用,那么我建议尝试使用PHPMailer而不是PHPGmailer-并在此处按照教程进行操作: http : //www.web-development-blog.com/archives/send-e-mail-messages-via-smtp -with-phpmailer-and-gmail /

Please, make sure: 请确保:

  • $mail->Username is equal to $mail->From , and is correct $mail->Username等于$mail->From ,并且是正确的
  • $mail->Password is correct $mail->Password正确
  • $mail->FromName does not contain "<" and ">" characters; $mail->FromName不包含“ <”和“>”字符; just try $mail->FromName = 'Test'; 只需尝试$mail->FromName = 'Test';

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM