PHP表单提交缺少电子邮件

时间:2013-11-05 15:15:48

标签: php html forms

我无法通过主机服务器将表单发送给我。我使用以下命令运行错误检查:

error_reporting( -1 );
ini_set( 'display_errors',1 );

if($success){
print "EmailTo: $EmailTo<br>".
    "Subject: $Subject<br>".
    "Body: $Message<br>".
    "From: $EmailFrom";
}

并返回正确的信息。

我的代码:

PHP:

<?php

$EmailFrom = Trim(stripslashes($_POST['Email']));
$EmailTo = "mclaypool@mac-av.com";
$Subject = "MAC Website Contact Form";
$Name = Trim(stripslashes($_POST['Name'])); 
$Address1 = Trim(stripslashes($_POST['Address1'])); 
$Address2 = Trim(stripslashes($_POST['Address2'])); 
$City = Trim(stripslashes($_POST['City'])); 
$State = Trim(stripslashes($_POST['State'])); 
$Zip = Trim(stripslashes($_POST['Zip'])); 
$Country = Trim(stripslashes($_POST['Country'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Phone = Trim(stripslashes($_POST['Phone'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address1: ";
$Body .= $Address1;
$Body .= "\n";
$Body .= "Address2: ";
$Body .= $Address2;
$Body .= "\n";
$Body .= "City: ";
$Body .= $City;
$Body .= "\n";
$Body .= "State: ";
$Body .= $State;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $Zip;
$Body .= "\n";
$Body .= "Country: ";
$Body .= $Country;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";


// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\n");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>MAC Production Contact Form</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="stylesheet" type="text/css" href="css/form.css" />
</head>

<body>

<div id="page-wrap">

    <img src="images/title.gif" alt="A Nice &amp; Simple Contact Form" /><br /><br />
    <p>Please fill in the following fields and we will get back to.</p>

    <div id="contact-area">
      <form method="post" action="contactengine.php">
            <label for="Name">Name:</label>
            <input type="text" name="Name" id="Name" />

            <label for="Address1">Address</label>
            <input type="text" name="Address1" id="Address1" />
            <label for="Address2"></label>
            <input type="text" name="Address2" id="Address2" />

            <label for="City">City:</label>
            <input type="text" name="City" id="City" />

            <label for="State">State:</label>
            <input type="text" name="State" id="State" />      

            <label for="Zip">Zip/Postal Code:</label>
            <input type="text" name="Zip" id="Zip" />                

            <label for="Country">Country:</label>
            <input type="text" name="Country" id="Country" />                               

            <label for="Email">Email:</label>
            <input type="text" name="Email" id="Email" />

            <label for="Phone">Phone Number:</label>
            <input type="text" name="Phone" id="Phone" />                

            <label for="Message">Message:</label><br />
            <textarea name="Message" rows="20" cols="20" id="Message"></textarea>

            <input type="submit" name="submit" value="Submit" class="submit-button" />
        </form>

        <div style="clear: both;"></div>

        <p>&nbsp;</p>

    </div>

</div>

电子邮件未被标记为垃圾邮件。当我最初创建网站并发送电子邮件时,表单在服务器上工作,没有任何问题。主持人改变了他们的网络服务器,我假设这是导致问题的原因,但是在我生气之前要确定。我在服务器上设置了2个表单,一个是输入代码列出的表单,另一个是插入的错误报告。 2个链接位于:

http://www.mac-av.com/form/

http://www.mac-av.com/form/index_test.html

1 个答案:

答案 0 :(得分:0)

email_from地址是否正确存储在数据库中?我以前遇到过“ - ”没有存储的问题..即mclaypool@mac-av.com