Jump to content

PHPmailer help


Gomo

Recommended Posts

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.
post-200146-0-68455600-1485655441_thumb.png

Also, "Access for less secure apps" has been enabled on my Gmail account.

 

Any help would be greatly appreciated!

 

-kind regards-

Gomo

Link to comment
Share on other sites

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#ASPs

Thanks for the help!

 

p.s both TLS and SSL settings/ports work fine

Edited by Gomo
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.