我是PHP的新手。我正在尝试使用PHP发送带附件的电子邮件。 但邮件加载了身体本身的所有附件内容而不是作为附件..
这是我的PHPcode
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
$random_hash = md5(date('r', time()));
$headers .= "\r\nContent-Type: multipart/mixed;
boundary=\"PHP-mixed-".$random_hash."\"";
// Set your file path here
$attachment = chunk_split(base64_encode(file_get_contents("images.jpg")));
//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative;
boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain;
charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the html message.
$message .= $htmlbody;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
//include attachment
$message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip;
name=\"logo.png\"\r\n"."Content-Transfer-Encoding:
base64\r\n"."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
输出是:
--PHP-mixed-702d78a6f5c1602c03250f197d9c8f50
Content-Type: multipart/alternative;
boundary="PHP-alt-702d78a6f5c1602c03250f197d9c8f50"
--PHP-alt-702d78a6f5c1602c03250f197d9c8f50
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Your Mail Contant Here.... You can use html tags here...
--PHP-alt-702d78a6f5c1602c03250f197d9c8f50--
--PHP-mixed-702d78a6f5c1602c03250f197d9c8f50
Content-Type: application/zip;
name="logo.png"
Content-Transfer-Encoding:
base64
Content-Disposition: attachment
/9j/4AAQSkZJRgABAgEASABIAAD/4RSoRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA
AAABAAAAYgEbAAUAAAABAAAAagEoAAMAA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c30Wf8IzajYjLMh7X2SytjGkM0gvOs7R9H0G+z+upv6L0++9+Rks+0uc5rmizhgYGhlbGt
9uz27/f+eqU+Yr0cRlEDt/0Y/oMhhwj0gXt4RH/dOb0y37fhGzLYQWugvI21v8DVqW/yXqd3T6zW
QxgcBqYaNPD2tCsdSyMjFZbZY5jmbpoYyWHX/B2fvf11zVf1nd9qLtz6n1FrqiWyHPB1p9n+DfX7
FBGM8kzKAqPXh1bOPHMwGvFTq34FN1P2h7a8b05AyGP9EyNPdWPb/wBuLnx1HAGQcc5HrNZ9O8N2
scXmGt0c7ftWh1TqfSOp4gtyaocTtexsyHt/N9v/AIEuV6jg9Nr2uL3sxC8bn1GXHd7W+pXYD/Nv
/cVvl8cZenIJg7DS/wDF/wC8WTx5NDfDEa149noPszMgWZXJ0QWxpZ24AAAAHZGVmYXVs
dAAAAAtiZ0NvbG9yVHlwZWVudW0AAAARRVNsaWNlQkdDb2xO7zabuHBEkkd/23NxZrAj2atABJ
SAfs/wBjopk28u1VNB0ku04qOv2hksdSzPLJVw1Bq5EdVeCcfuIKWJiWZyTqP9Dz7HnKd1Mu829x
unieGlAKKOAwPTy69s9vuBu2uYwIY42pXGaefA8egWq3JUlHJJF93U/wAKocYsYmd1FRK4
WwGkkPXHNt3zJOgazRoY4uK9vAf6YGpP/FdDnlE3e2bNa2JQyTAASGua4rknrPsH...
请帮我解决这个问题。
浏览了很多,虽然我是PHP的新手,无法解决我的问题
提前致谢..
答案 0 :(得分:1)
乍一看,您的代码看起来不错,但是您有Content-Disposition: attachment
尝试Content-Disposition: inline