I use phpmailer
to send messages. I used with my Gmail account to be sent ok, but When I change account on other (new account) I gets an error.
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Username and password are correct. I must something change in my mail settings?
Code:
<?php
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@gmail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
$mail->Host = gethostbyname('smtp.gmail.com');
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl'; // TCP port to connect to
$mail->CharSet = 'UTF-8';
$mail->setFrom($_POST['email'], 'Wiadomosc');
$mail->addAddress('xyz@gmail.com', ''); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Wiadomość ze strony Akademia Uwodzenia';
$mail->Body = 'Imię: '.$_POST['imie'].'<br>Nazwisko: '.$_POST['nazwisko'].'<br>Wiadomość: '.$_POST['wiadomosc'].'';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I have openssl. Sending works for my gmail account. After the data is changed to another account - company account. The code is not working.
Message from SMTP Debug
2016-01-09 11:22:08 Connection: opening to ssl://173.194.220.108:465,
timeout=300, options=array ( ) 2016-01-09 11:22:08 Connection: opened 2016-01-
09 11:22:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP b74sm14107051lfb.32 -
gsmtp 2016-01-09 11:22:08 CLIENT -> SERVER: EHLO localhost 2016-01-09 11:22:08
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [158.75.89.196] 250-SIZE
35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2016-01-
09 11:22:08 CLIENT -> SERVER: AUTH LOGIN 2016-01-09 11:22:08 SERVER ->
CLIENT: 334 VXNlcm5hbWU6 2016-01-09 11:22:08 CLIENT -> SERVER:
Yml1cm91d29kemVuaWFAZ21haWwuY29t 2016-01-09 11:22:08 SERVER -> CLIENT: 334
UGFzc3dvcmQ6 2016-01-09 11:22:08 CLIENT -> SERVER: a29iaWV0YTkw 2016-01-09
11:22:09 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 b74sm14107051lfb.32 - gsmtp 2016-
01-09 11:22:09 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 b74sm14107051lfb.32 - gsmtp
2016-01-09 11:22:09 SMTP Error: Could not authenticate. 2016-01-09 11:22:09
CLIENT -> SERVER: QUIT 2016-01-09 11:22:09 SERVER -> CLIENT: 221 2.0.0 closing
connection b74sm14107051lfb.32 - gsmtp 2016-01-09 11:22:09 Connection: closed
2016-01-09 11:22:09 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be
sent.Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Problem solved: