I have search many similar questions asked before but I still cannot find the solving method for this. Sorry for asking this question.
Below is my php coding using to send email:
<?php
require("class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "testingtesting0330@gmail.com"; // SMTP username
$mail->Password = "xxxxxxxx"; // SMTP password
$mail->From = "testingtesting0330@gmail.com";
$mail->AddAddress("testingtesting0330@gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi!
This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
The class.phpmailer.php file is placed in the same file with the previous php document. I have also changed the content of class.phpmailer.php as follow:
var $Host = 'ssl://smtp.gmail.com';
var $Port = 465;
I have also change the content of php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = testingtesting0330@gmail.com
The openssl function is also enabled in php.ini:
extension=php_openssl.dll
It also show openssl enabled in php info.
But after this, the error did show again. So, I would like to ask for the solution for this.
Also, if I need to connect to a certain SMTP server, only change the coding and php.ini is enough?
Thank you guy very much. This is very important to me and hope this problem can be solved.
After you guy helping me, I have tried more method to solve the problem.
I have change the SMTPSecure from "ssl" to "tls".
$mail->SMTPSecure = 'tls';
The error change from "SMTP -> ERROR: Password not accepted from server" to "SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known"
Further, if I changed the host from smtp.gmail.com to my IP address,
the error became "ERROR: Failed to connect to server: connection attempt failed because the connection object has for some time did not respond correctly, or connection establishment failed because the host connection can not respond"
Many thanks to all of you.
I think there is an issues with the server firewall. Can you please try to stop server firewall for testing purpose and check this again.