0

我无法让我的表格通过我的主机服务器向我发送电子邮件。我使用以下方法运行错误检查:

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

4

1 回答 1

0

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

于 2013-11-05T18:20:41.570 回答