2016-11-14 145 views
0

嗨,我使用smtp最新文件,並檢查網上所有的解決方案,我的SMTP php郵件工作本地主機不工作在服務器我的服務器的網絡郵件工作Fine.First我插入數據到我的數據庫然後那些數據我想要發送管理員電子郵件ID我的數據插入數據庫也郵件發送工作正常本地主機,但給服務器上的錯誤,它給服務器連接失敗。我與我的託管服務器支持論壇與我們聯繫,但他們說這是你的代碼問題 這是我的PHP代碼SMTP郵件不工作服務器在本地主機上工作精細

<?php 
    if(isset($_POST['Isubmit'])){ 
    $rname= $_POST['Iname']; 
    $remail= $_POST['Iemail']; 
    $rcontact= $_POST['Icontact']; 
    $rmessage= $_POST['Icomment']; 
    $rcourse= $_POST['Icourse']; 
    $date=date("Y-m-d"); 
$sql=mysqli_query($connect,"INSERT INTO enquiry(`NAME`,`EMAIL_ID`,`MOBILE_NO`,`COMMENT`,`SUBJECT`,`IS_DELETED`,`DATE`)VALUES('".$rname."','".$remail."','".$rcontact."','".$rmessage."','".$rcourse."','1','".$date."')"); 

//Mail Send Code 


$ToEmail = '[email protected]'; 
$EmailSubject = 'Site contact form'; 
$MESSAGE_BODY = "Dear Sir/Mam,"."\n" ."\n"."New Contact Details are - "."\n"."\n"; 
$MESSAGE_BODY .= "Full Name: ".$rname."\n"."\n"; 
$MESSAGE_BODY .= "Email: ".$remail."\n"."\n"; 
$MESSAGE_BODY .= "Phone: ".$rcontact."\n"."\n"; 
$MESSAGE_BODY .= "Message: ".$rmessage."\n"."\n"; 
$MESSAGE_BODY .= "Course: ".$rcourse."\n"."\n"; 
//SMTP needs accurate times, and the PHP time zone MUST be set 
//This should be done in your php.ini, but this is how to do it if you don'thave access to that date_default_timezone_set('Etc/UTC'); 
     require 'PHPMailer-master/PHPMailerAutoload.php'; 
     //Create a new PHPMailer instance 
    $mail = new PHPMailer; 
    //Tell PHPMailer to use SMTP 
    $mail->isSMTP(); 
    //Enable SMTP debugging // 0 = off (for production use) 
    $mail->SMTPDebug = 0; 
//Ask for HTML-friendly debug output 
    $mail->Debugoutput = 'html'; 
//Set the hostname of the mail server 
    $mail->Host = 'smtp.gmail.com'; 
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 
      $mail->Port = 465; 
    //Set the encryption system to use - ssl (deprecated) or tls 
     $mail->SMTPSecure = 'ssl'; 
    //Whether to use SMTP authentication 
    $mail->SMTPAuth = true; 
//Username to use for SMTP authentication - use full email address for gmail 
     $mail->Username = "[email protected]";//"[email protected]"; 
    //Password to use for SMTP authentication 
    $mail->Password = "yourpassword";//"[email protected]"; 
     //Set who the message is to be sent from 
     $mail->setFrom('[email protected]', 'Admin'); 
     $mail->addAddress($ToEmail); 
     //Set the subject line 
     $mail->Subject = 'Enquiry Mail'; 
     $mail->Body = $MESSAGE_BODY;//'this is test msg on 25-jun.'; 
     if(!$mail->Send()) { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
     } else { 
      echo "Message sent!<br>"; 
      } 
     } 
+1

您是否善良並向我們解釋您的問題與MySQL之間的關係?謝謝。 – FDavidov

回答

0

啓用SMTP調試

$mail->SMTPDebug = 1; 

OR

$mail->SMTPDebug = 2; 

然後錯誤info會給你更多關於錯誤的信息

if (!$mail->Send()) 
{ 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
    echo "Message sent!<br>"; 
} 
+0

服務器遇到內部錯誤或配置錯誤,無法完成您的請求。 –

+0

客戶端 - >服務器:EHLO服務器名稱 客戶端 - >服務器:AUTH LOGIN 客戶端 - >服務器:aHJkcHJlc3RpZ2Vwb2ludEBnbWFpbC5jb20 = 客戶端 - >服務器:cHJlc3RpZ2Vwb2ludEAxMjM = SMTP錯誤:密碼命令失敗: SMTP錯誤:無法驗證。 客戶端 - >服務器:退回 SMTP connect()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 郵寄程序錯誤:SMTP連接()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting –

+0

在兩臺服務器上依次顯示錯誤 –

相關問題