我正在使用 php 5.2 版。该脚本在 000webhost 中工作,但是当我使用 yahoo 网络主机时它不起作用

Im using php version 5.2. The script is working in 000webhost, but when i use yahoo web host it doesnt work

有人可以帮助解释为什么我的脚本在 yahoo 虚拟主机中不起作用,但它在 000webhost 中起作用。我正在使用 phpmailer5.2 和 Phpversion 5.2.12

错误是连接失败。错误 #2:stream_socket_client() [function.stream-socket-client]:无法连接到 smtp.gmail.com:587(没有到主机的路由)[/products/phpmailer/class.smtp.php第304行] 2018-12-06 03:50:16 SMTP 错误:无法连接到服务器:没有到主机的路由 (65) SMTP 连接 () 失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

<?php
$result="";
if (isset($_POST['submit'])) {
require_once ('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;

$mail->isSMTP();
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='sample@gmail.com';
$mail->Password='';

$mail->setFrom($_POST['email'],$_POST['name']);
$mail->addAddress('');
$mail->addAddress('');
$mail->addAddress('');
$mail->addReplyTo($_POST['email'],$_POST['name']);

$mail->isHTML(true);
$mail->Subject='Form Submission: '.$_POST['subject'];
$mail->Body='<h1 align=center>Name: '.$_POST['name'].'<br>Email: ' .$_POST['email']. '<br>Company: ' .$_POST['company'].'<br>Position: ' .$_POST['position'].'<br>Current System Used: '.$_POST['system']. '<br>Message: ' .$_POST['msg'].'</h1>';

if (!$mail->send()) {

  $result="Something went wrong please try again.";

}
else{

  $result="Thanks ".$_POST['name']." sending your request. ";
}

}

?>

您的 post 上的错误很明显。

您有 "no route to host",所以,问题是您的虚拟主机阻止了您连接到 gmail 服务器。