2017-01-17 159 views
0

我一直使用PHPmailer與GoDaddy託管的網站發生500內部服務器錯誤;我已經嘗試了幾種與我的挑戰相關的StackOverflow解決方案,但都沒有成功。PHPmailer - 500內部服務器錯誤

這裏是我的代碼:

require 'phpmailer/PHPMailerAutoload.php'; 
$feedback=''; 
$flag = array(); 
if(isset($_POST["submitlogin"]) and $_SERVER['REQUEST_METHOD'] == "POST"){ 

    $name = seo_friendly_url($_POST['name']); 
    $email = seo_friendly_url($_POST['email']); 
    $subject = seo_friendly_url($_POST['subject']); 
    $message = seo_friendly_url($_POST['message']); 

    //Email 

    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { 
     $feedback="Invalid email format"; 
     array_push($flag,"false"); 
    }else { 
     array_push($flag,"true"); 
    } 
    //Email 

    //Name 
    if (preg_match('/^[-a-zA-Z0-9._]+$/', $name)){ 
     array_push($flag,"true"); 
    }else { 
     $feedback="Invalid name format"; 
     array_push($flag,"false"); 
    } 
    //Name 


    if (!in_array("false", $flag)) { 

     //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't have access to that 
     date_default_timezone_set('Etc/UTC'); 

     //Create a new PHPMailer instance 
     $mail = new PHPMailer; 
     //Tell PHPMailer to use SMTP 
     $mail->isSMTP(); 
     //Enable SMTP debugging 
     // 0 = off (for production use) 
     // 1 = client messages 
     // 2 = client and server messages 
     $mail->SMTPDebug = 2; 
     //Ask for HTML-friendly debug output 
     $mail->Debugoutput = 'html'; 
     //Set the hostname of the mail server 
     $mail->Host = "smtpout.asia.secureserver.net"; 
     //Set the SMTP port number - likely to be 25, 465 or 587 
     $mail->Port = 25; 
     //Whether to use SMTP authentication 
     //$mail->Username = '[email protected]'; 
     //$mail->Password = 'password'; 
     $mail->SMTPAuth = false; 
     //Set who the message is to be sent from 
     $mail->setFrom('[email protected]'); 
     //Set an alternative reply-to address 
     $mail->addReplyTo($email); 
     //Set who the message is to be sent to 
     $mail->addAddress('[email protected]');  // Add a recipient 
     $mail->addAddress('[email protected]'); 
     $mail->addAddress('[email protected]); 
     //Set the subject line 
     $mail->Subject = 'HLS Inquiry'; 
     //Read an HTML message body from an external file, convert referenced images to embedded, 
     //convert HTML into a basic plain-text alternative body 
     $mail->msgHTML($message); 







     $email_ar = $email; 
     $subject_ar = $name.", Thank you for your Inquiry"; 
     $acknowledgement_receipt = ' 
      <div style="padding:10px 20px;font-size:16px;"> 

       <p>Dear '.$name.',</p> 

       <p>We&#39;ve received your message and would like to thank you for contacting us. We will reply by email shortly.</p> 

       <p>Talk to you soon,</p> 

       <p> 
        <div>Customer Service</div> 

       </p> 

      </div> 
     '; 



     if ($mail->send()) { 
      $feedback = "<span style='color:green;'>Thank you for your inquiry. We will respond to you within 24 hours.</span>"; 
     } 

} 

請注意,我更換了一些電子郵件值的:[email protected]了我的隱私。

我認爲,電子郵件的設置是正確的,因爲我已經從我的朋友的網站主辦Justhost的使用這些設置。

+0

嘗試用雙引號替換addAddress('[email protected]') - > addAddress(‘[email protected]’) –

回答

0

此行缺少一個單引號:

$mail->addAddress('[email protected]); 

這是SO很明顯的,因爲你可以看到語法在這一點突出休息。

當你得到一個錯誤500,顯示什麼,那就是你應該尋找在你的web服務器的錯誤日誌的標誌。

+0

我試圖把缺少的單引號,但仍然沒有工作:( 我在哪裏可以看到服務器日誌? – ASCII

+0

通常在'/ var/log/apache2/error.log'或類似的地方。 – Synchro