0
我試圖發送一封帶有多個附件的電子郵件......第一次嘗試此操作並卡住了,它成功發送帶有附件的電子郵件,但是作爲單個文件... 當然,如果我有兩個文件的100kb
1.jpg
和100kb
2.jpg
它會用附件發送電子郵件作爲200kb
這裏一個文件就是我的代碼多個文件作爲一個文件附件發送
<html>
<head>
<title>Sending attachment using PHP</title>
</head>
<body>
<?php
$to = "[email protected]";
$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:[email protected]\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...";
}
?>
什麼問題?你解決了嗎? – realtebo