im trying to send an email just when somebody enters on a page. It's for paypal payment confirmation. You pay something and in the page where you see what you did an email is send automatically.
The code is the next:
function send_email($from, $to, $subject, $nombre,$apellido) {
$pagoReal = $_SESSION["Payment_Amount"];
$monedaReal = $_SESSION["currencyCodeType"];
$estado = $_SESSION['estado'];
$id = $_SESSION['idHash'];
$mail = new PHPMailer();
$mail->SMTPDebug=3;
$mail->IsSMTP();
$mail->Host = 'localhost';
$mail->CharSet = "UTF-8";
$mail->From = $from;
$mail->FromName = 'Notificación de pago via Paypal';
$mail->addAddress($to);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->SMTPAuth = true;
$contenido = "<html><body>
<p>Han realizado un nuevo ingreso via Paypal</p><br>
Nombre del cliente: $nombre $apellido<br>
Cantidad que pagó: $pagoReal $monedaReal <br>
Estado de la reserva:$estado <br>
Enlace a la factura : href='xxxxx/$id<br>
</body></html>";
$mail->Subject = $subject;
$mail->Body = $contenido;
['tmp_name'],$_FILES['cv_contacto']['name']);
if (!$mail->Send()) {
echo 'Error enviando mensaje.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
return "Mailer Error: " . $mail->ErrorInfo;
} else {
return 1;
}
}
then i call the function
send_email('patata@patata.com', 'fran@patata.es','Payment of '. $firstName." ".$lastName,$firstName,$lastName);
And I get this error
Error: authentication failed: generic failure 2016-07-11 14:20:51 SMTP ERROR: Password command failed: 535 5.7.8 Error: authentication failed: generic failure 2016-07-11 14:20:51 CLIENT -> SERVER: QUIT 2016-07-11 14:20:51 SERVER -> CLIENT: 221 2.0.0 Bye 2016-07-11 14:20:51 Connection: closed 2016-07-11 14:20:51 SMTP connect() failed. Error enviando mensaje.Mailer Error: SMTP connect() failed.
Any idea of what can i do?
Thanks!
Follow this steps.
I was trying doing a lot of tests (hours and hours...), but the best configuration is: - "Allow less secure apps: ON". Sometimes this change will take effect after 10 minutes. - Use SSL configuration and port 465, LOGIN. - It´s better if you can activate the debbuging messages to know other details. - Some SMTP like gmail, requires to configure the IP address to accept the verification process (https://support.google.com/accounts/answer/6010255) - All this configurations also will be required in the Admin Panel on GSuite in case that you use a bussiness edition.
Regards, hope helps
I have resolved this issue :
Please follow the below steps :
1) Firstly download latest PHPmailer files. https://github.com/PHPMailer/PHPMailer
2) Google now doesn't accept login from less secure apps.
Open link : https://myaccount.google.com/security
3) Script code :
I hope its working fine.
Thanks