我正在尝试发送带有多个附件的电子邮件...第一次尝试并卡住了,它成功发送了带有附件的电子邮件,但作为单个文件...例如,如果 我1.jpg
有两个100kb
文件将带有附件的电子邮件作为单个文件发送,
这就是我的代码2.jpg
100kb
200kb
<html>
<head>
<title>Sending attachment using PHP</title>
</head>
<body>
<?php
$to = "abc@ex.com";
$subject = "This is subject";
$message = "This is test message.";
# Open a file
$file = "http://bestwallpaperhd.com/wp-content/uploads/2013/03/hot-girl-wallpaper.jpg";
$content = file_get_contents( $file);
# encode the data for safe transit
# and insert \r\n after every 76 chars.
$encoded_content = chunk_split( base64_encode($content));
$content1 = file_get_contents('http://www.albnews.al/wp-content/uploads/2013/08/99163-hot-girl_original.jpg');
$encoded_content1 = chunk_split( base64_encode($content1));
# Get a random 32 bit number using time() as seed.
$num = md5( time() );
# Define the main headers.
$header = "From:admin@hotesttube.com\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; ";
$header .= "boundary=$num\r\n";
$header .= "--$num\r\n";
# Define the message section
$header .= "Content-Type: text/plain\r\n";
$header .= "Content-Transfer-Encoding:8bit\r\n\n";
$header .= "$message\r\n";
$header .= "--$num\r\n";
# Define the attachment section
$header .= "--$num--";
$header .= "Content-Type: multipart/mixed; ";
$header .= "name=\"hotgirl.php\"\r\n";
$header .= "Content-Transfer-Encoding:base64\r\n";
$header .= "Content-Disposition:attachment; ";
$header .= "filename=\"hotgirl.jpg\"\r\n\n";
$header .= "$encoded_content\r\n";
$header .= "--$num--";
$header .= "--$num--";
$header .= "Content-Type: multipart/mixed; ";
$header .= "name=\"hotgirl123.php\"\r\n";
$header .= "Content-Transfer-Encoding:base64\r\n";
$header .= "Content-Disposition:attachment; ";
$header .= "filename=\"hotgirl123.jpg\"\r\n\n";
$header .= "$encoded_content1\r\n";
$header .= "--$num--";
# Send email now
$retval = mail ( $to, $subject, "", $header );
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>