将PHP表单更改为永久发送者


Change PHP Form to Permanent Sender

当有人在我们的网站上填写表单时,它会使用填写表单的人的电子邮件地址。我们的托管公司屏蔽了这些邮件,因为填写表格的人被设置为"发件人"。来自我们的托管公司:

"你需要确保表单是用DreamHost永久设置的托管的电子邮件地址,以便此表单正常工作而不会被拒绝。可以设置它,以便将填写表单的人设置为"From",这将导致上述拒绝。

只需编辑表单,使'From'永久设置为DH用户由于政策原因,表格不再被拒绝。"

我需要对下面的代码做什么更改才能使Dreamhost接受?如有任何帮助,我将不胜感激。

    <?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "eileenw@ourdomain.com";
$email_subject = "Quiz";
$your_email = "info@ourdomain.com";

function died($error) {
    // your error code can go here
    echo "<p>We are very sorry, but there were error(s) found with the form you submitted.</p> ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "<p>Please go back and fix these errors.<br /><br /></p>";
    die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');      
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$address = $_POST['address']; // not required
$city = $_POST['city']; // not required
$state = $_POST['state']; // not required
$vehicleyear = $_POST['vehicleyear']; // not required
$vehiclemake = $_POST['vehiclemake']; // not required
$vehiclemodel = $_POST['vehiclemodel']; // not required
$purchase_or_lease = $_POST['purchase_or_lease']; // not required
$deliverydate = $_POST['deliverydate']; // not required
$mileage_at_delivery = $_POST['mileage_at_delivery']; // not required
$current_mileage = $_POST['current_mileage']; // not required
$seller = $_POST['seller']; // not required
$citystate = $_POST['citystate']; // not required
$Bank_Finance = $_POST['Bank_Finance']; // not required
$dealer_arranged = $_POST['dealer_arranged']; // not required
$employee_discount = $_POST['employee_discount']; // not required
$warranty = $_POST['warranty']; // not required
$length_contract = $_POST['length_contract']; // not required
$comments = $_POST['comments']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+'.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does 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($first_name)."'n";
$email_message .= "Last Name: ".clean_string($last_name)."'n";
$email_message .= "Email: ".clean_string($email_from)."'n";
$email_message .= "Telephone: ".clean_string($telephone)."'n";
$email_message .= "Address: ".clean_string($address)."'n";
$email_message .= "City: ".clean_string($city)."'n"; 
$email_message .= "State: ".clean_string($state)."'n";
$email_message .= "Vehicle Year: ".clean_string($vehicleyear)."'n";
$email_message .= "Make: ".clean_string($vehiclemake)."'n";
$email_message .= "Model: ".clean_string($vehiclemodel)."'n";
$email_message .= "Purchase or Lease: ".clean_string($purchase_or_lease)."'n";
$email_message .= "Delivery date: ".clean_string($deliverydate)."'n";
$email_message .= "Mileage at Delivery: ".clean_string($mileage_at_delivery)."'n";
$email_message .= "Current Mileage: ".clean_string($current_mileage)."'n";
$email_message .= "Selling Dealer: ".clean_string($seller)."'n";
$email_message .= "Seller City and State: ".clean_string($citystate)."'n";
$email_message .= "Bank or Finance Company: ".clean_string($Bank_Finance)."'n";
$email_message .= "Dealer Arranged: ".clean_string($dealer_arranged)."'n";
$email_message .= "Employee Discount? ".clean_string($employee_discount)."'n";
$email_message .= "Warranty: ".clean_string($warranty)."'n";
$email_message .= "Contract Terms: ".clean_string($length_contract)."'n";
$email_message .= "Comments: ".clean_string($comments)."'n";

// create email headers
$headers = 'From: ' . $your_email . "'r'n";
'Reply-To: '.$email_from."'r'n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

根据您的主机提供商:

只需编辑表单,使'From'永久设置为DH用户

因此,如果我要猜测,我怀疑您需要做的更改是修改From标头。这是你设置它的地方:
$headers = 'From: ' . $your_email . "'r'n";

所以将它设置为其他内容:

$headers = 'From: someknownaddress@dreamhost.com' . "'r'n";