好一切都發送罰款,除了從我的電腦瀏覽的PDF文件。解析錯誤發送錯誤發送PDF
我的代碼現在看起來像這樣。
<?php
$ip = getenv('REMOTE_ADDR');
$hostname = gethostbyaddr($ip);
$email_to = "[email protected]";
$email_subject = "My subject";
$fullname = $_POST['fullname'];
$institution = $_POST['institution'];
$month = $_POST['month'];
$Day = $_POST['Day'];
$year = $_POST['year'];
$courses = $_POST['courses'];
$marital_status = $_POST['marital_status'];
$cover_letter = $_POST['cover_letter'];
$file_name = $_FILES['resume']['name'];
$file_size = $_FILES['resume']['size'];
$file_type = $_FILES['resume']['type'];
$tmp_name = $_FILES['resume']['tmp_name'];
$email_msg = "IP: $ip\n Host Name: $hostname\n Name in Full : $fullname\n Institution: $institution\n DOB : $month/$Day/$year\n Courses: $courses\n Marital Status: $marital_status\n Cover Letter : $cover_letter\n\n";
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers = "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" ;
$message = "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" .
$email_msg . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_type};\n" .
" name=\"{$tmp_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$tmp_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";
$sendmemail = @mail($email_to, $email_subject, $email_msg, $headers);
if($sendmemail)
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Registeration Complete')
window.location.href='[url]';
</SCRIPT>");
}
?>
該代碼現在工作100%,但它只發送捕獲的參數和沒有PDF文件。 我究竟在哪裏得到它全錯了?
您嘗試打開的文件不存在。首先解決它。 – Mei
我從我的桌面上瀏覽它。或者你的意思是它應該得到文件的擴展名? – RealMary
錯誤表示您試圖用'fopen()'打開的文件不存在。 – Tom