2014-11-25 22 views
1

您好,我正在用pdd/doc附件發​​送一封電子郵件。當我點擊發送電子郵件時,我收到一封正確附件的電子郵件,但我沒有收到郵件正文部分的郵件內容。當我點擊查看節目原創時,我可以在原始內容中看到該內容,但在電子郵件中看不到。 這是我的代碼。任何人都可以幫助我知道如何讓他們在正確的地方?使用附件發送電子郵件時身體部位丟失

<?PHP 

session_start(); 

$applicant_name = (isset($_POST["applicant_name"])) ? $_POST["applicant_name"] : ''; 
$applicant_age = (isset($_POST["age"])) ? $_POST["age"] : ''; 
$applicant_gender = (isset($_POST["gender"])) ? $_POST["gender"] : ''; 
$preferred_email = (isset($_POST["preferred_email"])) ? $_POST["preferred_email"] : ''; 
$MobileNo = (isset($_POST["preferred_mobile_no"])) ? $_POST["preferred_mobile_no"] : ''; 
$_SESSION['jobTitle']; 
$_SESSION['jobId']; 

$pdf_doc=''; 

if(isset($_FILES['document_url']['name'])){ 
$pdf_doc = rand() . "_" . $_FILES['document_url']['name']; 
copy($_FILES['document_url']['tmp_name'], "job_docs/" . $pdf_doc); 
} 

$name = $applicant_name; 
$email = "[email protected]"; 
$to = "Karda <".$email.">"; 
$from = $preferred_email; 
$subject = "Application for post : ".$_SESSION['jobTitle']."[".$_SESSION['post_id']."]"; 

$mainMessage = "<br/>Applicant Name :-&nbsp;" . $applicant_name . "\n\n" 
    . "<br/>Email:-&nbsp;" . $preferred_email . "\n\n" 
    . "<br/>Phone:-&nbsp;" . $MobileNo . "\n\n" 
    . "<br/>Age:-&nbsp;" . $applicant_age . "\n\n" 
    . "<br/>Gender:-&nbsp;" . $applicant_gender . "\n\n"; 

$fileatt = "job_docs/".$pdf_doc; 
$fileatttype = "application/pdf"; 
$fileattname = "job_docs/".$pdf_doc; 

$headers = "From: $preferred_email"; 

// File 
$file = fopen($fileatt, 'rb'); 
$data = fread($file, filesize($fileatt)); 
fclose($file); 

// This attaches the file 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
$headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";   

$message = $mainMessage."This is a multi-part message in MIME format.\n\n" ."-{$mime_boundary}\n" ."Content-Type: text/plain; charset=\"iso-8859-1\n" ."Content-Transfer-Encoding: 7bit\n\n\n"; 


$data = chunk_split(base64_encode($data)); 

$message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatttype};\n" ." name=\"{$fileattname}\"\n" ."Content-Disposition: attachment;\n" ." filename=\"{$fileattname}\"\n" ."Content-Transfer-Encoding: base64\n\n" .$data . "\n\n" ."-{$mime_boundary}-\n"; 

// Send the email 

if(mail($to, $subject, $message, $headers)) { 

header("location:we_are_hiring.php"); 

} 

else { 

    header("location:index.php");; 

} 
?> 
+0

如果相關不知道,但你在這裏有一個額外的分號:'頭( 「地點:的index.php」)?; ;' – Jonast92 2014-11-25 10:52:07

+0

嘗試發送您的附件不在按摩頭。 – 2014-11-25 10:57:02

回答

0

您尚未正確格式化邊界標記。正確的語法如下:

MIME-Version: 1.0 
Content-Type: multipart/mixed; boundary="$boundary" 

This is a multi-part message in MIME format. 
--$boundary 
Content-Type: text/plain 

(message body) 

--$boundary 
Content-Type: image/jpeg; name="attachment.jpg" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename="attachment.jpg" 

(base64 attachment) 

--$boundary-- 

你的代碼有$boundary之前只是一個連字符在幾個地方。

0

你已經混有身體的一部分你的頭,seprate他們解決這個問題,這樣的事情:

<?PHP 

session_start(); 

$applicant_name = (isset($_POST["applicant_name"])) ? $_POST["applicant_name"] : ''; 
$applicant_age = (isset($_POST["age"])) ? $_POST["age"] : ''; 
$applicant_gender = (isset($_POST["gender"])) ? $_POST["gender"] : ''; 
$preferred_email = (isset($_POST["preferred_email"])) ? $_POST["preferred_email"] : ''; 
$MobileNo = (isset($_POST["preferred_mobile_no"])) ? $_POST["preferred_mobile_no"] : ''; 
$_SESSION['jobTitle']; 
$_SESSION['jobId']; 

$pdf_doc=''; 

if(isset($_FILES['document_url']['name'])){ 
$pdf_doc = rand() . "_" . $_FILES['document_url']['name']; 
copy($_FILES['document_url']['tmp_name'], "job_docs/" . $pdf_doc); 
} 

$name = $applicant_name; 
$email = "[email protected]"; 
$to = "Karda <".$email.">"; 
$from = $preferred_email; 
$subject = "Application for post : ".$_SESSION['jobTitle']."[".$_SESSION['post_id']."]"; 

$mainMessage = "<br/>Applicant Name :-&nbsp;" . $applicant_name . "\n\n" 
. "<br/>Email:-&nbsp;" . $preferred_email . "\n\n" 
. "<br/>Phone:-&nbsp;" . $MobileNo . "\n\n" 
. "<br/>Age:-&nbsp;" . $applicant_age . "\n\n" 
. "<br/>Gender:-&nbsp;" . $applicant_gender . "\n\n"; 

$fileatt = "job_docs/".$pdf_doc; 
$fileatttype = "application/pdf"; 
$fileattname = "job_docs/".$pdf_doc; 

$headers = "From: $preferred_email"; 

//文件 $文件=的fopen($ fileatt, 'RB'); $ data = fread($ file,filesize($ fileatt)); fclose($ file);

// This attaches the file 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
$headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" . " boundary=\"  {$mime_boundary}\"";   

$headers = "Content-Type: text/plain; charset=\"iso-8859-1\n" ."Content-Transfer-Encoding: 7bit\n\n\n"; 


$data = chunk_split(base64_encode($data)); 

$headers .= "--{$mime_boundary}\n" ."Content-Type: {$fileatttype};\n" ." name=\" {$fileattname}\"\n" ."Content-Disposition: attachment;\n" ." filename=\"{$fileattname}\"\n" ."Content-Transfer-Encoding: base64\n\n" .$data . "\n\n" ."-{$mime_boundary}-\n"; 

//發送電子郵件

if(mail($email, $subject, $mainMessage, $headers)) { 

header("location:we_are_hiring.php"); 

} 

else { 

header("location:index.php");; 

} >