问题描述:

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='[email protected]';

$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 = '[email protected]'; // 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('[email protected]', '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.

相关阅读:
Top