2015-05-04 85 views
1

我正在嘗試從表單向我的電子郵件發送數據。從網站發送表單數據到電子郵件時發生錯誤504

我嘗試使用我的服務器(免費託管)的形式,它很好。當我嘗試在另一臺服務器上使用它時(通過cloudflare運行),它會給我504網關錯誤。任何想法爲什麼?

它在我身邊還是我必須解決一些問題?

我的服務器頁:http://mywg1.x10host.com/m1/

的CloudFlare運行頁:http://wholesaledrywalltoronto.therenopros.ca/

窗體的PHP:

<?php 
if(isset($_POST['Email'])) { 

// EDIT THE 2 LINES BELOW AS REQUIRED 

$email_to = "[email protected]"; 
$email_subject = "Drywall Pros Form"; 

function died($error) { 
    // your error code can go here 

    echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
    echo "These errors appear below.<br /><br />"; 

    echo $error."<br /><br />"; 
    echo "Please go back and fix these errors.<br /><br />"; 

    die(); 
} 

// validation expected data exists 

if(!isset($_POST['Name']) || 
     !isset($_POST['Email']) || 
     !isset($_POST['Phone']) || 
     !isset($_POST['comments'])) { 
    died('We are sorry, but there appears to be a problem with the form you submitted.');  
} 

$Name = $_POST['Name']; // required 
$Email = $_POST['Email']; // required 
$Phone = $_POST['Phone']; // not required 
$comments = $_POST['comments']; // required 

$error_message = ""; 

$string_exp = "/^[A-Za-z .'-]+$/"; 

if(!preg_match($string_exp,$Name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
} 

if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
} 

if(strlen($error_message) > 0) { 
    died($error_message); 
} 

$email_message = "Form details below.\n\n"; 

function clean_string($string) { 
    $bad = array("content-type","bcc:","to:","cc:","href"); 
    return str_replace($bad,"",$string); 
} 

$email_message .= "First Name: ".clean_string($Name)."\n"; 
$email_message .= "Email: ".clean_string($Email)."\n"; 
$email_message .= "Phone: ".clean_string($Phone)."\n"; 
$email_message .= "Comments: ".clean_string($comments)."\n"; 

// create email headers 

$headers = 'From: '.$email_from."\r\n". 
    'Reply-To: '.$email_from."\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

mail($email_to, $email_subject, $email_message, $headers); 
?> 
<!-- include your own success html here --> 

Thank you for contacting us. We will be in touch with you very soon. 

<?php 
} 
?> 
+0

代碼格式,拼寫錯誤 – Voitcus

回答

0

固定它。對於有同樣錯誤的人。這可能是因爲您正在使用的服務器只允許SMTP而不是PHP郵件功能。