【问题标题】:Error 504 when sending form data from website to email将表单数据从网站发送到电子邮件时出现错误 504
【发布时间】:2015-05-05 00:46:26
【问题描述】:

我正在尝试将表单中的数据发送到我的电子邮件。

我尝试在我的服务器中使用该表单(免费托管),这很好。当我尝试在另一台服务器上使用它(通过 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.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.\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
}
?>

【问题讨论】:

  • 代码格式,拼写错误

标签: php hosting


【解决方案1】:

修复它。对于任何有同样错误的人。这可能是因为您使用的服务器只允许 SMTP 而不允许 PHP 邮件功能。

【讨论】:

    猜你喜欢
    • 2012-01-12
    • 1970-01-01
    • 2013-11-24
    • 2019-08-08
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    相关资源
    最近更新 更多