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
auth_username=example@gmail.com
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 ("example@pn.com") and other domain email such as test@gmail.com, test@yahoo.com 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 = "example@gmail.com";
$mail->Password = "password";
$mail->setFrom('test@gmail.com', 'First Last');
//$mail->addReplyTo('replyto@example.com', 'First Last');
$mail->addAddress('test@gmail.com', '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 ("example@pn.com").It does not work with other email domain such as gmail, yahoo etc. It says
Mailer Error: SMTP Error: The following recipients failed: test@gmail.com: Unable to relay
How to fix that problem ?
Thanks.