作者ps9956 (HhoHho)
看板PHP
标题[请益] 关於php寄信问题
时间Thu Jan 17 22:01:00 2008
各位大大好:
目前已经做好php线上寄信,SMTP也有设定,在网页上测试寄发信件
按传送却无法寄出,会出现档案下载的视窗!这是怎麽一回事呢?
为什麽无法将信寄出,却变成下载档案?? >_<??
程式码:(PHP部分)
<?php
$from_name = iconv("UTF-8", "Big5", $_POST{"from_name"});
$from_email = $_POST{"from_email"};
$to_name = iconv("UTF-8", "Big5", $_POST{"to_name"});
$to_email = $_POST{"to_email"};
$format = $_POST{"format"};
$subject = iconv("UTF-8", "Big5", $_POST{"subject"});
$message = iconv("UTF-8", "Big5", $_POST{"message"});
$mime_boundary = md5(uniqid(mt_rand(), TRUE));
$header = "From: $from_name <$from_email>\r\n";
$header.= "To: $to_name <$to_email>\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: multipart/mixed;\r\n";
$header.= " boundary=". $mime_boundary . "\r\n";
$content = "This is a multi-part message in MIME format.\r\n";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: text/$format; charset=Big5\r\n";
$content .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$content .= $message. "\r\n";
$content .= "--" . $mime_boundary . "\r\n";
if ($_FILES{"myfile"}{"size"} != 0)
{
$file = $_FILES{"myfile"}{"tmp_name"};
$fp = fopen($file, "rb");
$data = fread($fp, filesize($file));
$data = chunk_split(base64_encode($data));
$content .= "Content-Type: " . $_FILES{"myfile"}{"type"} . ";";
$content .= "name=". $_FILES{"myfile"}{"name"} . "\r\n";
$content.= "Content-Disposition: attachment; filename=";
$content .= $_FILES{"myfile"}{"name"} ."\r\n";
$content .= "Content-Transfer-Encoding: BASE64\r\n\r\n";
$content .= $data."\r\n";
$content .= "--" . $mime_boundary . "--\r\n";
}
mail($to_email, $subject, $content, $header);
?>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.60.11.253
1F:推 cleanwind:你不觉得该来个程式码吗 XD 01/17 22:48
※ 编辑: ps9956 来自: 210.60.11.253 (01/18 11:35)