2015-05-04 86 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邮件功能。