2015-10-20 197 views
3

大家好我是新的PHP和HTML和面临问题: SMTP错误:无法连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机。但在本地xampp中正常工作,并在服务器中出现错误。下面 代码: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 = "[email protected]"; 
    //$mail->Password = "gmail pass";  
    //$mail->SetFrom('[email protected]', 'Pankaj U'); 
    $mail->SetFrom($email); 
    $mail->AddReplyTo($email); 
    $mail->Subject = "Enquiry from Website"; 
    $mail->MsgHTML($msg); 
    $address = "[email protected]"; 
    $mail->AddAddress($address, $name); 
    if(!$mail->Send()) { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
     header('Location: thanks.html'); 
    } 
?> 
+0

你需要检查你的防火墙 –

+0

但在本地服务器工作正常? –

回答

4
$mail->SMTPSecure = "tls"; 
$mail->Port  = 587; 
相关问题