Reputation: 23
PHPMailer 5.2 keeps telling me, that I cannot send out an e-mail.
I know the credentials are proper (firefox checks e-mails, laravel sends out emails).
Which setting/command am I missing?
PHP code:
$mail->isSMTP();
$mail->Host = ******;
$mail->SMTPAuth = true;
$mail->Username = ******;
$mail->Password = ******;
$mail->SMTPSecure = false;
$mail->Port = 25;
$mail->SMTPDebug = 3;
$mail->SMTPOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
SMTP Debug:
2017-03-22 19:06:14 Connection: opening to *************:25, timeout=300, options=array (
'ssl' =>
array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
),
)
2017-03-22 19:06:14 Connection: opened
2017-03-22 19:06:14 SERVER -> CLIENT: 220 ************* ESMTP Postfix
2017-03-22 19:06:14 CLIENT -> SERVER: EHLO *******
2017-03-22 19:06:14 SERVER -> CLIENT: 250-*************
250-PIPELINING
250-SIZE 15728640
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN CRAM-MD5
250-AUTH=PLAIN LOGIN CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
2017-03-22 19:06:14 CLIENT -> SERVER: STARTTLS
2017-03-22 19:06:14 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-03-22 19:06:14 CLIENT -> SERVER: EHLO *******
2017-03-22 19:06:14 SERVER -> CLIENT: 250-*************
250-PIPELINING
250-SIZE 15728640
250-ETRN
250-AUTH PLAIN LOGIN CRAM-MD5
250-AUTH=PLAIN LOGIN CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
2017-03-22 19:06:14 CLIENT -> SERVER: AUTH CRAM-MD5
2017-03-22 19:06:14 SERVER -> CLIENT: 334 ***********************************
2017-03-22 19:06:14 CLIENT -> SERVER: **************************************
2017-03-22 19:06:16 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: ***********************************
2017-03-22 19:06:16 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: ***********************************
2017-03-22 19:06:16 SMTP Error: Could not authenticate.
2017-03-22 19:06:16 CLIENT -> SERVER: QUIT
2017-03-22 19:06:16 SERVER -> CLIENT: 221 2.0.0 Bye
2017-03-22 19:06:16 Connection: closed
2017-03-22 19:06:16 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Upvotes: 2
Views: 9990
Reputation: 6637
AuthType should solve your problem:
$mail->AuthType = 'LOGIN';
other options include: PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2
https://phpmailer.github.io/PHPMailer/classes/SMTP.html#method_authenticate
Upvotes: 8
Reputation: 224
I don't know which commands are missing but my suggestion is use swift mailer instead of php mailer. following code is useful to send mail using swift mailer. You can download swift mailer library from following link and make sure you download swift 5.0.1.
<?php
require_once 'Swift-5.0.1/lib/swift_required.php';
// Grab the Data
$emailc=$emailid;
$name=filter_var(''.$name1.'',FILTER_SANITIZE_STRING);
$uname1=filter_var(''.$uname.'',FILTER_SANITIZE_STRING);
$psw1=filter_var(''.$psw.'',FILTER_SANITIZE_STRING);
$email=filter_var($emailc,FILTER_SANITIZE_EMAIL);
// Create our body messag
$data = "Nanme:".$name."<br>Your username is <b>".$uname1."</b> and password is <b>".$psw1."</b> ";
//Create the transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',587,'tls')
->setUsername('[email protected]')
->setPassword('xyz121212');
// Create the mailer
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Demo')
->setFrom (array('[email protected]' => 'Demo'))
->setTo (array(''.$email.'' => 'Add Recipients'))
->setSubject ('Thanks, This mail is for remind your appoinment')
->setBody ($data, 'text/html');
// Send the message
$result = $mailer->send($message);
?>
Upvotes: 1