如何设置转发邮件地址?

时间:2011-04-04 03:12:59

标签: php html

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

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "info@jadescientific.com.my";
    $email_subject = "Request form sent from jadescientific.com.my";


    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['company_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['product_interested'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $name = $_POST['name']; // required
    $company_name = $_POST['company_name']; // required\
    $email= $_POST['email']; // not required
    $telephone= $_POST['telephone']; // not required
    $product_interested= $_POST['product_interested']; // required

    $error_message = "";
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "^[a-z ./'-]+$";
  if(!eregi($string_exp,$name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }
    if(!eregi($string_exp,$company_name)) {
    $error_message .= 'The Company Name you entered does not appear to be valid.<br />';
  }
     $varchar1_exp = "^[0-9 .'-]+$";
   if(!eregi($varchar1_exp,$telephone)) {
    $error_message .= 'The telephone you entered does not appear to be valid.<br />';
  }

  if(strlen($product_interested) < 2) {
    $error_message .= 'The product interested 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 .= "Name: ".clean_string($name)."\n";
    $email_message .= "Company Name: ".clean_string($company_name)."\n";
    $email_message .= "Email Address: ".clean_string($email)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Product Interested: ".clean_string($product_interested)."\n";


// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\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.

<?
}
?>

1 个答案:

答案 0 :(得分:0)

这是最适合你的方式

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required


$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(($email_from != "") && !eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';