[英]How to send HTML email with attachment?
I am using mail()
function of PHP, following is my code; 我正在使用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);
But I dont know why, in email I am only getting attachment, I am not getting candidate name . 但是我不知道为什么,在电子邮件中我只得到附件,而没有得到候选人姓名 。 I mean html contents. 我的意思是html内容。
I am moving to PHPMailer and I am using this code, 我正在使用PHPMailer,并且正在使用此代码,
if (isset($_FILES['uploaded_file']) &&
$_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
$_FILES['uploaded_file']['name']);
}
for attachment. 用于附件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.