I've been trying to setup my localhost to send messages from a contact form to a test Gmail account that I've setup. When I run the file I get this error:
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known.
Here's the code
require_once('phpmailer/PhpMailerAutoload.php');
$subject='Test Email';
$from='random_email_from_contact_form@example.com';
$message='This is a test email.';
$mail=new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.google.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mytestmail@gmail.com'; // SMTP username
$mail->Password = 'myemailpassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SMTPDebug = 1;
$mail->setFrom($email, 'Joe Smith');
$mail->addAddress('mytestmail@gmail.com', 'Me'); // Add a recipient
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
I have the email set to receive less secure apps. I also changed the settings so that IMAP is enabled.
extension=php_openssl.dll
is also uncommented in the php.ini
file also.