附件不在邮件PHP中显示

时间:2016-12-15 06:56:47

标签: php

我正在研究表格,所有事情都运转良好。但问题是,当用户附加文件时,它将出现在服务器上,但不会显示在我的收件箱中。请帮我解决这个问题。这是我的PHP代码:

<?php
include('conn/conn.php');
if(isset($_POST['Submit'])){
$name                   =   $_POST['name'];
$email                  =   $_POST['email'];
$mobile                 =   $_POST['mobile'];
$age                    =   $_POST['age '];
$gender                 =   $_POST['gender'];
$city                   =   $_POST['city'];
$presentquali           =   $_POST['presentquali'];
$experience             =   $_POST['experience'];
$sapcertificate         =   $_POST['sapcertificate'];
$yearobtain             =   $_POST['yearobtain'];
$currentsalary          =   $_POST['currentsalary'];
$expectedsalary         =   $_POST['expectedsalary'];
$skills                 =   $_POST['skills'];
$designation            =   $_POST['designation'];
$jobprofile             =   $_POST['jobprofile'];
$passport               =   $_POST['passport'];
$clientsideexp          =   $_POST['clientsideexp'];
$countryname            =   $_POST['countryname'];
$germanlanguage         =   $_POST['germanlanguage'];
$germanlanguagelevel    =   $_POST['germanlanguagelevel'];
$relocate               =   $_POST['relocate'];
$maritalstatus          =   $_POST['maritalstatus'];
$query                  =   $_POST['query'];    

$t_email = array("abc@dummy.net");
// multiple recipients
foreach($t_email as $key=>$index){
$to = $t_email[$key];

// subject
$subject = 'Enquiry Details';

// message
$message = '
<html>
<head>
<title>Enquiry Details</title>
</head>
<body>
<p>Here are the Detail- </p>
<table>
';
if($name!=''){
$message .= '
<tr>
<td>Name -</td>
<td>'.$name.'</td>
</tr>
    ';
    }
    if($email!=''){
    $message .= '
        <tr>
          <td>Email -</td>
          <td>'.$email.'</td>
        </tr>

    ';
    }
    if($mobile!=''){
    $message .= '
        <tr>
          <td>Mobile -</td>
          <td>'.$mobile.'</td>
        </tr>
    ';
    }
    if($age!=''){
    $message .= '
        <tr>
          <td>Age -</td>
          <td>'.$age.'</td>
        </tr>
    ';
    }
    if($gender!=''){
    $message .= '
        <tr>
          <td>Gender -</td>
          <td>'.$gender.'</td>
        </tr>
    ';
    }
    if($city!=''){
    $message .= '
        <tr>
          <td>Present Location City -</td>
          <td>'.$city.'</td>
        </tr>
    ';
    }
    if($presentquali!=''){
    $message .= '
        <tr>
          <td>Qualification -</td>
          <td>'.$presentquali.'</td>
        </tr>
    ';
    }
    if($experience!=''){
    $message .= '
        <tr>
          <td>Experience in Years -</td>
          <td>'.$experience.'</td>
        </tr>
    ';
    }
    if($sapcertificate!=''){
    $message .= '
        <tr>
          <td>SAP Certification -</td>
          <td>'.$sapcertificate.'</td>
        </tr>
    ';
    }
    if($yearobtain!=''){
    $message .= '
        <tr>
          <td>Year-In Obtained -</td>
          <td>'.$yearobtain.'</td>
        </tr>
    ';
    }
    if($currentsalary!=''){
    $message .= '
        <tr>
          <td>Salary in INR/Per Month -</td>
          <td>'.$currentsalary.'</td>
        </tr>
    ';
    }
    if($expectedsalary!=''){
    $message .= '
        <tr>
          <td>Expected Salary -</td>
          <td>'.$expectedsalary.'</td>
        </tr>
    ';
    }
    if($skills!=''){
    $message .= '
        <tr>
          <td>Skills -</td>
          <td>'.$skills.'</td>
        </tr>
    ';
    }
    if($designation!=''){
    $message .= '
        <tr>
          <td>Designation -</td>
          <td>'.$designation.'</td>
        </tr>
    ';
    }
    if($jobprofile!=''){
    $message .= '
        <tr>
          <td>Brief Job Profile/Role -</td>
          <td>'.$jobprofile.'</td>
        </tr>
    ';
    }
    if($passport!=''){
    $message .= '
        <tr>
          <td>Have Passport Y/N -</td>
          <td>'.$passport.'</td>
        </tr>
    ';
    }
    if($clientsideexp!=''){
    $message .= '
        <tr>
          <td>Client Side / On-site Experience Yes/No -</td>
          <td>'.$clientsideexp.'</td>
        </tr>
    ';
    }
    if($countryname!=''){
    $message .= '
        <tr>
          <td>If Yes Countries visited -</td>
          <td>'.$countryname.'</td>
        </tr>
    ';
    }
    if($germanlanguage!=''){
    $message .= '
        <tr>
          <td>Knowledge of German or DutchLanguage -</td>
          <td>'.$germanlanguage.'</td>
        </tr>
    ';
    }
    if($germanlanguagelevel!=''){
    $message .= '
        <tr>
          <td>If Yes proficiency in Languages: (Excellent/Good/Average) -</td>
          <td>'.$germanlanguagelevel.'</td>
        </tr>
    ';
    }
    if($relocate!=''){
    $message .= '
        <tr>
          <td>Time required to relocate to Germany /Holland -</td>
          <td>'.$relocate.'</td>
        </tr>
    ';
    }
    if($maritalstatus!=''){
    $message .= '
        <tr>
          <td>Married/Single -</td>
          <td>'.$maritalstatus.'</td>
        </tr>
    ';
    }
    if($query!=''){
    $message .= '
        <tr>
          <td>Query -</td>
          <td>'.$query.'</td>
        </tr>
    ';
    }

    $message .= '
        </table>
    </body>
    </html>
    ';



    //attachment
    if(isset($_FILES['fileupload'])){
      $errors= array();
      $file_name = $_FILES['fileupload']['name'];
      $file_size = $_FILES['fileupload']['size'];
      $file_tmp = $_FILES['fileupload']['tmp_name'];
      $file_type = $_FILES['fileupload']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['fileupload']['name'])));

      $expensions= array("doc","docx");

      if(in_array($file_ext,$expensions)=== false){

         //things we need
         $file = $file_name;
         $content = chunk_split(base64_encode(file_get_contents($file)));
         $uid = md5(uniqid(time()));

         //declaring we have multiple kinds of email
         $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
         $header .= "This is a multi-part message in MIME format.\r\n";

         //plain text part
         $header .= "--".$uid."\r\n";
         $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
         $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
         $header .= $message."\r\n\r\n";

         //file attached
         $header .= "--".$uid."\r\n";
         $header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
         $header .= "Content-Transfer-Encoding: base64\r\n";
         $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n";
         $header .= $content."\r\n\r\n";

        $errors[]="File type not allowed.";
      }

      if($file_size > 2097152) {
         $errors[]='File size must be excately 2 MB';
      }

      if(empty($errors)==true) {
         move_uploaded_file($file_tmp,"resume/".$file_name);
      }else{
         print_r($errors);
      }
   }
   //attachment end


    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    //$headers .= 'To: test <test@example.com>, check <check@example.com>' . "\r\n";
    $headers .= 'From: Senior SAP Consultants Job Opportunities<info@server.com>' . "\r\n";
    //$headers .= 'Cc: test@example.com' . "\r\n";
    //$headers .= 'Bcc: test@example.com' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);
}
}; 
?>

0 个答案:

没有答案