i want to send email through my website but i got an issue that smtp connection is failed every time.
i had used the port tls 587 and ssl 465 but every time smtp connection failed. I am using PHPMailer 5.2.22 in previous days this code is working well but now this is creating problem. please give me some idea to solve this issue
code:
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $name;
$InputEmail = $email;
$InputContact = $_POST['number1'];
$InputAddress = $_POST['city1'];
$InputMessage = $_POST['message1']." is th message.";
$mail->isSMTP(); // Set mailer to use SMTP
//$mail->Host = 'bh-26.webhostbox.net'; // Specify main and backup server
//$mail->SMTPDebug = 4;
$mail->Host = 'mail.gmail.com';
$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->SMTPSecure = false;
// SMTP password
$mail->Username = 'blabla@gmail.com';
$mail->Password = 'xyz123@ddd';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('blabla@gmail.com', 'bla');
$mail->addAddress('test@gmail.com','test');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'User Details';
$mail->Body = '<table>'
.'<tr ><td width="150px">User Name: <b>'.$name.'</b></td></tr>'."\r\n"
.'<tr><td>User Email : <b><a href = \"#\">'.$InputEmail.'</a></b></td></tr>'."\r\n"
.'<tr><td>User Contact No. : <b>'.$InputContact.'</b></td></tr>'."\r\n"
.'<tr><td>User Message : <b>'.$InputMessage.'</b></td><tr>'."\r\n"
.'<tr><td>User Agent : <b>'.$user_agent.'</b></td></tr>'."\r\n"
.'</table>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo "Email Sent Successfully.";
Error is : 2018-09-04 06:54:46 Connection: opening to mail.gmail.com:587, timeout=300, options=array () 2018-09-04 06:54:48 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known. 2018-09-04 06:54:48 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to mail.gmail.com:587 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) 2018-09-04 06:54:48 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) 2018-09-04 06:54:48 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed