用于将表单数据发送到多个电子邮件的PHP代码

时间:2014-08-13 07:22:14

标签: php email

我正在尝试将表单数据发送到多个电子邮件地址,下面是我的PHP代码,我得到的问题是我在第二个电子邮件ID(email2@domain.com)中只收到一封邮件而不是第一封邮件(email1@domain.com)。任何人都可以帮助我。

我的PHP代码在这里:

<?php require_once('../../connections/formsqlconnection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

//Defining form variables
        $title = $_POST['title'];  
        $firstname = $_POST['first_name'];  
        $lastname = $_POST['last_name'];
        $dob = $_POST['dob'];
        $address = $_POST['address'];  
        $city = $_POST['city'];  
        $postcode = $_POST['postal_code'];  
        $country = $_POST['country'];
        $phone1 = $_POST['phone1'];
        $phone2 = $_POST['phone2'];
        $mobile1 = $_POST['mobile1'];
        $mobile2 = $_POST['mobile2'];
        $email1 = $_POST['email1'];
        $email2 = $_POST['email2'];
        $compname = $_POST['company_name'];
        $compadd = $_POST['company_address'];
        $compdetails = $_POST['company_details'];
        $aop = $_POST['area_of_product'];
        $website = $_POST['website'];
        $nat = $_POST['nationality'];
        $cor = $_POST['country_of_res'];
        $memtype = $_POST['member_type'];
        $idproof = $_POST['idproof'];

//This is to generate vendor code and product code
$c1=$_POST['city'][0];
$c2=$_POST['first_name'][0];
$c3=$_POST['last_name'][0];
$date = date("dmy");
$vendor_code = "VH".$c1.$c2.$c3.$date;
$product_code = "VH".$c1.$c2.$c3;

//Writes the Idproof file to the server and generates URL to save in database
if ($img = $_FILES["file_idproof"]["tmp_name"]) {
        $image_url = md5_file($img) . ".jpeg";
        move_uploaded_file($img, "../../upload/$image_url");
        $image_url = "http://www.angelron.5gbfree.com/upload/$image_url";
}

//Posting to the database
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO vendor_details (vendor_code, product_code, date_of_joining, title, first_name, last_name, dob, address, city, postal_code, country, phone1, phone2, mobile1, mobile2, email1, email2, company_name, company_details, company_address, area_of_product, website, nationality, country_of_res, member_type, id_proof, file_idproof) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($vendor_code, "text"),
                       GetSQLValueString($product_code, "text"),
                       GetSQLValueString($_POST['date_of_joining'], "text"),
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['dob'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['postal_code'], "text"),
                       GetSQLValueString($_POST['country'], "text"),
                       GetSQLValueString($_POST['phone1'], "text"),
                       GetSQLValueString($_POST['phone2'], "text"),
                       GetSQLValueString($_POST['mobile1'], "text"),
                       GetSQLValueString($_POST['mobile2'], "text"),
                       GetSQLValueString($_POST['email1'], "text"),
                       GetSQLValueString($_POST['email2'], "text"),
                       GetSQLValueString($_POST['company_name'], "text"),
                       GetSQLValueString($_POST['company_details'], "text"),
                       GetSQLValueString($_POST['company_address'], "text"),
                       GetSQLValueString($_POST['area_of_product'], "text"),
                       GetSQLValueString($_POST['website'], "text"),
                       GetSQLValueString($_POST['nationality'], "text"),
                       GetSQLValueString($_POST['country_of_res'], "text"),
                       GetSQLValueString($_POST['member_type'], "text"),
                       GetSQLValueString($_POST['id_proof'], "text"),
                       GetSQLValueString($image_url, "text"));

  mysql_select_db($database_formsqlconnection, $formsqlconnection);
  $Result1 = mysql_query($insertSQL, $formsqlconnection) or die(mysql_error());


//This is the code to send mail  
        $emailID = "email1@domain.com , email2@domain.com";
        $subject = "New vendor ($firstname) registered through our website";
$body = <<<EOD

        <table cellspacing="0" cellpadding="1" border="1">
            <tbody>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Vendor Code: </td>
                    <td style="padding: 5px 10px;">$vendor_code</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Product Code: </td>
                    <td style="padding: 5px 10px;">$product_code</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Name: </td>
                    <td style="padding: 5px 10px;">$firstname $lastname</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Company Name: </td>
                    <td style="padding: 5px 10px;">$compname</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Area of Products: </td>
                    <td style="padding: 5px 10px;">$aop</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Mobile: </td>
                    <td style="padding: 5px 10px;">$mobile1</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Email: </td>
                    <td style="padding: 5px 10px;">$email1</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Website: </td>
                    <td style="padding: 5px 10px;">$website</td>
                </tr>
                <tr>
                    <td style="padding: 5px 10px;" width="150">Address: </td>
                    <td style="padding: 5px 10px;">$address, $city, $postcode, $country</td>
                </tr>
            </tbody>
        </table>

EOD;

        $headers = "From: website@company.com\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
        $headers .= "X-Priority: 1\r\n";
        $headers .= "X-MSMail-Priority: High\n";
        $headers .= "X-Mailer: PHP". phpversion() ."\r\n";

        mail($emailID, $subject, $body, $headers );

//On successful submit go to confirm page
  $insertGoTo = "../confirm.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

1 个答案:

答案 0 :(得分:0)

也许将邮件分开?

mail('email1@domain.com', $subject, $body, $headers);
mail('email2@domain.com', $subject, $body, $headers);