我正在使用以下代码将附件发送到电子邮件...但我无法收到电子邮件..
我能够获得成功发送邮件的消息,例如“已发送消息”,但电子邮件不会发送到相应的邮件 ID。
我不知道我哪里做错了......
这是php文件...
<?php
if(isset ($_POST["send"]))
{
$upload_name=$_FILES["upload"]["name"];
$upload_type=$_FILES["upload"]["type"];
$upload_size=$_FILES["upload"]["size"];
$upload_temp=$_FILES["upload"]["tmp_name"];
$message=$_POST["msg"];
$subject = $_POST["subject"];
$to=$_POST["to"];
if($message==""||$subject==""||$to=="")
{
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Please fill all fields</font>';
}
else
{
$fp = fopen($upload_temp, "rb");
$file = fread($fp, $upload_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//普通头
$headers = "From: Info Mail<Info@example.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// 这两个步骤有助于避免垃圾邮件
$headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// 有消息
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// 附件头
$headers .= "Content-Type:".$upload_type." ";
$headers .= "name=\"".$upload_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$upload_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// 发邮件
mail($to, $subject, $message, $headers);
fclose($fp);
echo '<font style="color:#333333">Mail sent please check inbox and spam both <br /></font>';
}
}
?>
//表单详细信息和添加附件的HTML代码..
<form id="attach" name="attach" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>" enctype="multipart/form-data">
//Html code for mail details
</form>
我收到“警告:mail() [function.mail]:mail() 函数的参数错误,邮件未发送....”并且它还显示“已发送的邮件请检查收件箱和垃圾邮件”.. 是什么问题 ?
帮我解决这个问题...