Gomo Posted January 29, 2017 Share Posted January 29, 2017 Hello guys, I've been trying to get my PHPmailer to work for quite some time now. What am I doing wrong here? (I keep getting this error message "Message could not be sent.Mailer Error: SMTP connect() failed") This is the PHP code: <?php require 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'test@gmail.com'; // SMTP username $mail->Password = 'test'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to $mail->setFrom('test@gmail.com', 'Mailer'); $mail->addAddress('test1@gmail.com'); // Add a recipient //$mail->addAddress('ellen@example.com'); // Name is optional //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name //$mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'Name:'.$_POST['field1'].'<br /> Surname:'.$_POST['field2'].'<br /> Phone:'.$_POST['field3'].'<br /> Email:'.$_POST['field4'].'<br /> Subject:'.$_POST['field5'].'<br /> Message:'.$_POST['field6'].''; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?> Contents of my "phpmailer" folder.Also, "Access for less secure apps" has been enabled on my Gmail account. Any help would be greatly appreciated! -kind regards- Gomo Quote Link to comment https://forums.phpfreaks.com/topic/303050-phpmailer-help/ Share on other sites More sharing options...
Jacques1 Posted January 29, 2017 Share Posted January 29, 2017 Read the troubleshooting guide. Turn debug output all the way up so that you get concrete messages (for some strange reason, you've commented this out). Try 'tls' on port 587 rather than the nonstandard 465 port . Quote Link to comment https://forums.phpfreaks.com/topic/303050-phpmailer-help/#findComment-1542081 Share on other sites More sharing options...
Gomo Posted January 29, 2017 Author Share Posted January 29, 2017 (edited) Did a bit more digging, and managed to fix the problem. This setting was causing problems: App passwords not working If you’ve double-checked to make sure you’ve entered the App Password in correctly but it’s still not working, try going to https://g.co/allowaccess on your device’s browser. Enter your username and password, then type the letters on the screen. Then go back to the application you're trying to access and enter your App Password. https://support.google.com/accounts/answer/185834?hl=en#ASPsThanks for the help! p.s both TLS and SSL settings/ports work fine Edited January 29, 2017 by Gomo Quote Link to comment https://forums.phpfreaks.com/topic/303050-phpmailer-help/#findComment-1542083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.