0

I am tring to use PHPMailer for sending mail with pdf attachment.

Code :

    include_once("./PHPMailer/PHPMailerAutoload.php");
    $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 = 'tls'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 587; // or 587
    $mail->IsHTML(true);
    $mail->Username = "[email protected]";
    $mail->Password = "accual password";
    $mail->SetFrom("[email protected]");
    $mail->Subject = "Test";
    $mail->Body = "hello";
    $mail->AddAddress("[email protected]");

    if (!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message has been sent";
    }

Error :

2016-10-25 10:40:27 CLIENT -> SERVER: EHLO test.something.com
2016-10-25 10:40:27 CLIENT -> SERVER: STARTTLS
2016-10-25 10:40:27 CLIENT -> SERVER: EHLO test.something.com
2016-10-25 10:40:27 CLIENT -> SERVER: AUTH LOGIN
2016-10-25 10:40:27 CLIENT -> SERVER: ... user name removed ... 
2016-10-25 10:40:27 CLIENT -> SERVER: ... password removed ...
2016-10-25 10:40:27 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials cy7sm4615595wjc.26 - gsmtp
2016-10-25 10:40:27 SMTP Error: Could not authenticate.
2016-10-25 10:40:27 CLIENT -> SERVER: QUIT
2016-10-25 10:40:27 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshootingthanks

How Can I resove this problem? I appreciate all response. Thanks ahead.

4

2 Answers 2

1

The error message states quite clearly what the (most likely) problem is:

Username and Password not accepted.

So double-check that the username and password is correct, and that there aren't any charset issues with them. Tried doing a quick search to find out what kind of charset the STMP server expects, but couldn't find anything specific.

Also, you might want to check the link included in the error message, as well as the gmail SMTP support page. More specifically, this bit:

To connect with SSL, you need to provide a Google username and password for authentication. Ensure that the username you use has cleared the CAPTCHA word verification test that appears when the user first logs in. We also recommend ensuring that the account has a secure password.

0
1

Please read the error messages that you are receiving. They clearly state that your password is incorrect. Since the SMTP output did include your user name and password, I tried to log in and gmail reports that your password is incorrect:

PLEASE CHANGE YOUR PASSWORD IMMEDIATELY AND SANITIZE ERROR MESSAGES BEFORE ADDING THEM TO A QUESTION

2

Not the answer you're looking for? Browse other questions tagged or ask your own question.