$pdfname="test.pdf"; $email="test@test.com"; $text = "您好,附件中是您需要的pdf檔案。請點擊下載。<br><a href=http://www.111cn.net>www.111cn.net</a>"; //常值內容 $text = base64_encode($text); //用base64方法把它編碼 $text = chunk_split($text); //把這個長字串切成由每行76個字元組成的小塊 $subject = $pdfname; //標題 $from = "admin@111cn.net"; //寄件者 $to = $email; //接受者 //附件 // 定義分界線 $boundary = "nextpart_".uniqid(""); $boundary2 = "nextpart_".uniqid(""); $headers = "to: $torn"; $headers .= "from: $fromrn"; $headers .="mime-version: 1.0rn"; $headers .= "content-type: multipart/mixed; boundary="----=_$boundary"rn"; $read=file_get_contents($pdfname); $read = base64_encode($read); //用base64方法把它編碼 $read = chunk_split($read); //把這個長字串切成由每行76個字元組成的小塊 //現在我們可以建立郵件的主體 $body = "this is a multi-part message in mime format. ------=_$boundary content-type: multipart/alternative; boundary="----=_$boundary2"; ------=_$boundary2 content-type: text/html; charset="gbk" content-transfer-encoding: base64 $text ------=_$boundary2-- ------=_$boundary content-type: application/octet-stream; charset="gbk"; name="$pdfname" content-disposition: attachment; filename="$pdfname" content-transfer-encoding: base64 $read -------=_$boundary--"; if(mail($to, $subject,$body,$headers)) echo "您需要的pdf檔案(".$pdfname.")已經發往您的郵箱:".$to."。<br>請查收。"; else echo "抱歉,發送失敗了。<br>"; |