如何发送附带附件的HTML电子邮件?

时间:2015-05-13 12:31:56

标签: php email

我正在使用PHP的mail()函数, 以下是我的代码;

$to = "info@abc.com";
$subject = "Application for Job";
$attachment =chunk_split(base64_encode(file_get_contents($_FILES['attachresume']['tmp_name'])));
$filename = $_FILES['attachresume']['name'];

$boundary = md5(date('r', time()));

$headers = "From: info@xyz.com\r\nReply-To:  info@xyz.com";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

$message = "Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
<strong>Candidate Name :</strong> ".$candidatename."<br>
$message .="--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment $attachment --_2_$boundary--";

mail($to,$subject,$message,$headers);

但我不知道为什么,在电子邮件中我只是得到了依恋,我没有得到候选人姓名。我的意思是HTML内容。

1 个答案:

答案 0 :(得分:0)

我正在转向 PHPMailer 我正在使用此代码,

if (isset($_FILES['uploaded_file']) &&
    $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
                         $_FILES['uploaded_file']['name']);
}

附件。