PHPMailer didn't work in Windows Server 2012 - Unable to relay w/Gmail, Yahoo, etc ...

522 views Asked by At

I have a problem with PHPMailer inside my Windows Server 2012. I'm using XAMPP as my local server. I notice that i cannot ping smtp.gmail.com in my window server 2012. it says

ping request could not find host smtp.gmail.com. Please check and try again

I added this line in php.ini

[mail function]
smtp_server=smtp.gmail.com
smtp_port=25
sendmail_path ="\"D:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=On

And I added this line in sendmail.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=password
force_sender=
force_recipient=
hostname=localhost

I test my PHPMailer in my local PC, it works fine. I can send into my own domain email ("[email protected]") and other domain email such as [email protected], [email protected] etc. Here's my PHPMailer code.

testsend.php

<?php
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->setFrom('[email protected]', 'First Last');
//$mail->addReplyTo('[email protected]', 'First Last');
$mail->addAddress('[email protected]', 'John Doe');
$mail->Subject = 'PHPMailer GMail SMTP test';
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->Body = 'dfssf';
$mail->AltBody = 'This is a plain-text message body';
//$mail->addAttachment('images/phpmailer_mini.png');
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

But when I add similar PHPMailer folder and files inside my server, it only work when I send to my own domain which is ("[email protected]").It does not work with other email domain such as gmail, yahoo etc. It says

Mailer Error: SMTP Error: The following recipients failed: [email protected]: Unable to relay

How to fix that problem ?

Thanks.

0

There are 0 answers