Trying blocked Phpmailer login

Asked

Viewed 272 times

0

Good night,

I have a php code that sends a simple email to the user using a Gmail account, already activated the Access to less secure apps but I’m still getting that feedback:

2015-04-01 01:24:04
CLIENT -> SERVER: EHLO localhost 2015-04-01 01:24:05
CLIENT -> SERVER: AUTH LOGIN 2015-04-01 01:24:05
CLIENT -> SERVER: YW1hLmJ1Z3NAZ21haWwuY29t 2015-04-01 01:24:06
CLIENT -> SERVER: cnB5cGtrYzg2eA== 2015-04-01 01:24:06
SMTP ERROR: Password command failed: 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/bin/answer.py?answer=78754 91sm281474qkw.13 - gsmtp 2015-04-01 01:24:06
CLIENT -> SERVER: QUIT 2015-04-01 01:24:07 SMTP connect() failed.

[MAIL ERR]: SMTP connect() failed.

I tried some solutions I saw on the internet but I was not successful, follow my code snippet:

if ( $_SERVER["REQUEST_METHOD"] != "POST" ) {
    // Verifica se o POST está setado (existe)
    if ( !isset( $_POST ) ) {
        echo "error: post not set";
        exit();
    }
    echo "error: request is not a post";
    exit();
}

$mail_addr = utf8_decode( $_POST["mail"] );
$username  = utf8_decode( $_POST["username"] );

$dao = new UserDao();
$result = $dao->Select_GetUserID( $mail_addr );

$person_id = $result->id;

$html = file_get_contents("../view/template/template_mail.html");

$activate_url     = "localost/activate/"            + $person_id;
$donotdisturb_url = "localhost/account/notdisturb/" + $person_id;
$notmedude_url    = "localhost/account/notme/"      + $person_id;

$html = str_replace( '{USERNAME}',         htmlentities( $username ),  $html );
$html = str_replace( '{ACTIVATE_URL}',     htmlentities( $activate_url ),     $html );
$html = str_replace( '{DO_NOT_DISTURB}',   htmlentities( $donotdisturb_url ), $html );
$html = str_replace( '{IM_NOT_THIS_DUDE}', htmlentities( $notmedude_url ),    $html );

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Port       = 465;
$mail->Host       = "smtp.gmail.com";
$mail->IsHTML(true);
$mail->Mailer     = 'smtp';
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth   = true;
$mail->SMTPDebug  = 1;
$mail->Username   = "[email protected]";
$mail->Password   = "xxxxxxxxxx";

$mail->From       = "[email protected]";     // já tentei SetFrom
$mail->FromName   = "StayAround";
$mail->AddReplyTo( "xxxx" , "StayAround" );

$mail->AddAddress($mail_addr, $username);
$mail->Subject    = "Cadastro StayAround";
$mail->Body       = $html;

$send = $mail->Send();
$mail->ClearAllRecipients();

if ( $send ) {
    echo "mail sent";
    exit();
} else {
    echo "[MAIL ERR]: " . $mail->ErrorInfo;
    exit();
}

Thanks for your help.

1 answer

0

Already downloaded the latest version of Phpmailer? Apparently your code has nothing wrong, I tested it here and it worked perfectly. Check your password, exchange it and do simple test isolated as messages sent with the content 'Test'.

Hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.