1

I want to use the Mail function using PHPMailer in order to give an email confirmation for someone who filled a form.

Here's my send mail code =>

 /* some codes with already a phpmyadmin database and a form */


function send_mail($email,$message,$subject) // method called, ignore the param
    {                       
        require_once('mailer/class.phpmailer.php');
    $mail = new PHPMailer();

    $mail->IsSMTP();
    $mail->SMTPDebug = 2;
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';

    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; // for ssl
    $mail->Username = 'an_email_test_1@gmail.com';
    $mail->Password = 'pwd_of_username_just_above';

    $mail->SetFrom('an_email_test_1@gmail.com'); // same as ->Username
    $mail->Subject = "Test Mail";
    $mail->Body = "Hi.";
    $mail->AddAddress('an_email_test_2@gmail.com');

    if (!$mail->Send())
        return 'Mail error:' . $mail->ErrorInfo;
    return 'Success, check your mail.';
}

I get a "SMTP Class not found" so I included right below the require_once('mailer/class.phpmailer.php'); =>

        require 'mailer/PHPMailerAutoload.php';

and thanks the SMTPDebug enabled, it gives me this error >

2016-05-20 14:27:49 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:49 CLIENT -> SERVER: EHLO "name_of_my_virtualhost" (I use WAMP3.0.4)
2016-05-20 14:27:49 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [80.215.180.91] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 
2016-05-20 14:27:49 CLIENT -> SERVER: AUTH LOGIN 
2016-05-20 14:27:49 SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2016-05-20 14:27:49 CLIENT -> SERVER: bG9nYW4ucGV5cnkxQGdtYWlsLmNvbQ== 2016-05-20 14:27:49 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2016-05-20 14:27:49 CLIENT -> SERVER: Y29jaG9uOTM= 
2016-05-20 14:27:50 SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:50 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:50 SMTP Error: Could not authenticate. 
2016-05-20 14:27:50 CLIENT -> SERVER: QUIT 
2016-05-20 14:27:50 SERVER -> CLIENT: 221 2.0.0 closing connection h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:50 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

I don't really know how to solve it, I just wanted to send a simple mail without any informations for now with 2 gmail address created especially for that. The n°1 as the sender and the n°2 as the recipient

Should I change something from the apache php.ini in the mail function or something else ? Thanks for helping me :)

vimuth
  • 5,064
  • 33
  • 79
  • 116
rnerde
  • 11
  • 5
  • It would help if you read [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) that the error message pointed you at, or any of the many duplicates of this question. – Synchro May 20 '16 at 16:01

1 Answers1

0

Have you activeated the php_openssl extension in PHP

Using the menus do

wampmanager -> PHP -> PHP Extension -> php_openssl

If this menu item does not have a TICK beside it, click the php_openssl menu line and it will activate the extension and restart Apache for you so it see's the change.

You may also need to Allow less secure password on the accounts

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • I checked wampmanager settings and php_openssl was already marked. Furthermore, thanks to you, I change the account security of my mail sender with your link and now I received from my mail n°2, the mail as I wanted. Thanks for that but is it normal if the error message is still there with SMTPDebug ? – rnerde May 20 '16 at 15:33