Php 如何在mail()中组合两个标题

Php 如何在mail()中组合两个标题,php,Php,您好,我已经发布了这个问题,但我认为它有点复杂,所以我没有收到任何答案,我简单地说,我有两个标题,一个负责附件,另一个负责答复如何将它们合并成一个标题 这是两个标题 // this one is used for attachment. $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=

您好,我已经发布了这个问题,但我认为它有点复杂,所以我没有收到任何答案,我简单地说,我有两个标题,一个负责附件,另一个负责答复如何将它们合并成一个标题

这是两个标题

// this one is used for attachment.

$headers .= "\nMIME-Version: 1.0\n" .
                      "Content-Type: multipart/mixed;\n" .
                      " boundary=\"{$mime_boundary}\"";
-------------------------------------------------------------------------------------

// this one is used for reply

    'Reply-To: '.$emailadd."\r\n" .
          'X-Mailer: PHP/' . phpversion();
    $headers = 'From: '.$emailadd."\r\n".

-----------------------------------------------------------------------------------------

<?php
// Read POST request params into global vars
    // FILL IN YOUR EMAIL

    $email_to = "contact@scale-property.com";
    $email_subject = "New Property has received From Customer For Announcement ";
    $email_subject_to_user = "Copy OF Your Property Email Sent To Scale Property Website For Announcement";
    $propery_Information = 'PROPERTY INFORMATION';
    $propery_Location = 'PROPERTY LOCATION';
    $contact_Information = 'CONTACT INFORMATION';
    $property_status = $_POST['propertystatus']; // required
    $currency_type = $_POST['currencytype']; // required
    $currency = $_POST['currency']; // required
    $rooms = $_POST['rooms']; // required
    $bathroom = $_POST['bathroom']; // required
    $kitchen = $_POST['kitchen']; // required
    $yard = $_POST['yard']; // required
    $housedesproperty = $_POST['housedesproperty']; // required
    $drop_1 = $_POST['drop_1']; // required
    $drop_2 = $_POST['drop_2']; // required
    $drop_3 = $_POST['drop_3']; // required
    $region = $_POST['region']; // required
    $street = $_POST['street']; // required
    $name = $_POST['name']; // required
    $emailadd = $_POST['emailadd']; // required
    $conemailadd = $_POST['conemailadd']; // required
    $phone1 = $_POST['phone1']; // required
    $phone2 = $_POST['phone2']; // required

    // Allowed file types. add file extensions WITHOUT the dot.
    $allowtypes=array("zip", "rar");

    // Require a file to be attached: false = Do not allow attachments true = allow only 1 file to be attached
    $requirefile="true";

    // Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handel it,
    // post_max_size, upload_max_filesize, file_uploads, max_execution_time!
    // 2048kb = 2MB,       1024kb = 1MB,     512kb = 1/2MB etc..
    $max_file_size="1024";

    // Thank you message
    $thanksmessage="Your email has been sent, we will respond shortly.";

    $errors = array(); //Initialize error array

    //checks for a name
    if (empty($_POST['propertystatus']) ) {
        $errors[]='You forgot to enter your property status';
        }
    if (empty($_POST['currencytype']) ) {
        $errors[]='You forgot to enter your property currency type';
        }
    if (empty($_POST['currency']) ) {
        $errors[]='You forgot to enter your currency';
        }
    if (empty($_POST['rooms']) ) {
        $errors[]='You forgot to enter your rooms';
        }
    if (empty($_POST['bathroom']) ) {
        $errors[]='You forgot to enter your bathroom';
        }
    if (empty($_POST['kitchen']) ) {
        $errors[]='You forgot to enter your kitchen';
        }
    if (empty($_POST['yard']) ) {
        $errors[]='You forgot to enter your yard';
        }
    if (empty($_POST['housedesproperty']) ) {
        $errors[]='You forgot to enter your housedesproperty';
        }
    if (empty($_POST['drop_1']) ) {
        $errors[]='You forgot to enter your Province';
        }
    if (empty($_POST['drop_2']) ) {
        $errors[]='You forgot to enter your District';
        }
    if (empty($_POST['drop_3']) ) {
        $errors[]='You forgot to enter your PD(Nahya)';
        }
    if (empty($_POST['region']) ) {
        $errors[]='You forgot to enter your region';
        }
    if (empty($_POST['street']) ) {
        $errors[]='You forgot to enter your street';
        }
    if (empty($_POST['name']) ) {
        $errors[]='You forgot to enter your name';
        }
    if (empty($_POST['emailadd']) ) {
        $errors[]='You forgot to enter your emailadd';
        }
    if (empty($_POST['conemailadd']) ) {
        $errors[]='You forgot to enter your conemailadd';
        }
    if (empty($_POST['phone1']) ) {
        $errors[]='You forgot to enter your phone1';
        }
    if (empty($_POST['phone2']) ) {
        $errors[]='You forgot to enter your phone2';
        }

    // checks for required file
    // http://amiworks.co.in/talk/handling-file-uploads-in-php/
    if($requirefile=="true") {
        if($_FILES['attachment']['error']==4) {
            $errors[]='You forgot to attach a file';
        }
    }

    //checks attachment file
    // checks that we have a file
    if((!empty($_FILES["attachment"])) && ($_FILES['attachment']['error'] == 0)) {
            // basename -- Returns filename component of path
            $filename = basename($_FILES['attachment']['name']);
            $ext = substr($filename, strrpos($filename, '.') + 1);
            $filesize=$_FILES['attachment']['size'];
            $max_bytes=$max_file_size*1024;

            //Check if the file type uploaded is a valid file type. 
            if (!in_array($ext, $allowtypes)) {
                $errors[]="Invalid extension for your file: <strong>".$filename."</strong>";

        // check the size of each file
        } elseif($filesize > $max_bytes) {
                $errors[]= "Your file: <strong>".$filename."</strong> is to big. Max file size is ".$max_file_size."kb.";
            }

    } // if !empty FILES

    if (empty($errors)) { //If everything is OK

        // send an email
        // Obtain file upload vars
        $fileatt      = $_FILES['attachment']['tmp_name'];
        $fileatt_type = $_FILES['attachment']['type'];
        $fileatt_name = $_FILES['attachment']['name'];

        // Headers
        $headers = "From: $emailfrom";

        // create a boundary string. It must be unique
          $semi_rand = md5(time());
          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

          // Add a multipart boundary above the plain message
          $message ="This is a multi-part message in MIME format.\n\n";
          $message.="--{$mime_boundary}\n";
          $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
          $message.="Content-Transfer-Encoding: 7bit\n\n";
          $message.="From: ".$namefrom."\n";
          $message.="property status: ".$property_status."\n";
          $message.="currency type: ".$currency_type."\n";
          $message.="currency: ".$currency."\n";
          $message.="Rooms: ".$rooms."\n";
          $message.="Bathrooms: ".$bathroom."\n";
          $message.="Kitchen: ".$kitchen."\n";
          $message.="yard: ".$yard."\n";
          $message.="Describtion: ".$housedesproperty."\n";
          $message.="Kabul: ".$drop_1."\n";
          $message.="District: ".$drop_2."\n";
          $message.="PD(Nahya): ".$drop_3."\n";
          $message.="Region: ".$region."\n";
          $message.="Street: ".$street."\n";
          $message.="Name: ".$name."\n";
          $message.="Email ID: ".$emailadd."\n";
          $message.="Confirmation ID: ".$conemailadd."\n";
          $message.="Phone:(1) ".$phone1."\n";
          $message.="Phone(2): ".$phone2."\n";

        if (is_uploaded_file($fileatt)) {
          // Read the file to be attached ('rb' = read binary)
          $file = fopen($fileatt,'rb');
          $data = fread($file,filesize($fileatt));
          fclose($file);

          // Base64 encode the file data
          $data = chunk_split(base64_encode($data));

          // Add file attachment to the message
          $message .= "--{$mime_boundary}\n" .
                      "Content-Type: {$fileatt_type};\n" .
                      " name=\"{$fileatt_name}\"\n" .
                      //"Content-Disposition: attachment;\n" .
                      //" filename=\"{$fileatt_name}\"\n" .
                      "Content-Transfer-Encoding: base64\n\n" .
                      $data . "\n\n" .
                      "--{$mime_boundary}--\n";


                  // Add the headers for a file attachment
          $headers .= "\nMIME-Version: 1.0\n" .
                      "Content-Type: multipart/mixed;\n" .
                      " boundary=\"{$mime_boundary}\"";

        }


        // Send the completed message

        $envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
        foreach ($envs as $env)
        $message .= "$env: $_SERVER[$env]\n";


          $headers = 'From: '.$emailadd."\r\n".
          $headers .= 'Reply-To: '.$emailadd."\r\n" . 'X-Mailer: PHP/' . phpversion();


        if(@mail($email_to,$email_subject,$message,$headers) && @mail($emailadd,$email_subject_to_user,$message,$headers))

         {

            echo '<div id="formfeedback"><h3>Thank You!</h3><p>'. $thanksmessage .'</p></div>';
         } 

         else 

         {

            exit("Mail could not be sent. Sorry! An error has occurred, please report this to the website administrator.\n");

         } // end of if !mail

    } else { //report the errors
        echo '<div id="formfeedback"><h3>Error!</h3><p>The following error(s) has occurred:<br />';
        foreach ($errors as $msg) { //prints each error
                echo " - $msg<br />\n";
            } // end of foreach
        echo '</p><p>Please try again</p></div>';
    } //end of if(empty($errors))

?>
//这个用于附件。
$headers.=“\n时间版本:1.0\n”。
“内容类型:多部分/混合;\n”。
“边界=\”{$mime\u boundary}\”;
-------------------------------------------------------------------------------------
//这个是用来回复的
'回复:'.$emailadd.\r\n'。
“X-Mailer:PHP/”。phpversion();
$headers='From:'.$emailadd.\r\n。
-----------------------------------------------------------------------------------------
像这样:

$headers = 'From: '.$emailadd."\r\n".
$headers .= 'Reply-To: '.$emailadd."\r\n" . 'X-Mailer: PHP/' . phpversion();