dongyu5104 2015-05-04 04:14
浏览 140

将表单数据从网站发送到电子邮件时出错504

I am trying to send a data from a form to my email.

I try using the form in my server (free hosting) and it is fine. When I try to use it on another server (runs through cloudflare ) it gives me 504 gateway error. Any idea why?

Is it on my side or do I have to fix something?

My server page : http://mywg1.x10host.com/m1/

Cloudflare run page : http://wholesaledrywalltoronto.therenopros.ca/

the PHP for the form :

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

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "email.x@gmail.com";
$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.

";

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

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

// create email headers

$headers = 'From: '.$email_from."
".
  'Reply-To: '.$email_from."
" .
  '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
}
?>
  • 写回答

1条回答 默认 最新

  • duanji2014 2015-05-04 16:46
    关注

    Fixed it . For anyone who is having same errors . It is probably because the server you are working with only allows SMTP and not the PHP mail function.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗