大家好,我是php和html的新手,面临的问题:SMTP错误:无法连接到SMTP主机。邮件错误:SMTP错误:无法连接到SMTP主机。但是在本地示例中工作良好,并且在服务器中出现错误。下列代码:
<?php
$name = $_POST['name'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$company = $_POST['company'];
$message = $_POST['message'];
$msg= " <strong>Name:</strong> $name <br /> <strong>Contact:</strong> $contact <br /> <strong>Email:</strong> $email <br /><strong>Company:</strong> $company <br /><strong>Message:</strong> $message";
require_once('mailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
//$mail->Username = "me@domain.com";
//$mail->Password = "gmail pass";
//$mail->SetFrom('balajeeenterprises9@gmail.com', 'Pankaj U');
$mail->SetFrom($email);
$mail->AddReplyTo($email);
$mail->Subject = "Enquiry from Website";
$mail->MsgHTML($msg);
$address = "balajeeenterprises9@gmail.com";
$mail->AddAddress($address, $name);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header('Location: thanks.html');
}
?>
$mail->SMTPSecure = "tls";
$mail->Port = 587;