我使用以下代码将附件发送到电子邮件...但我无法收到电子邮件..
我能够收到成功发送邮件的消息,例如“已发送邮件”,但电子邮件不会转到相应的邮件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()函数,邮件未发送....”并且它还显示“邮件发送请检查收件箱和垃圾邮件” ..问题是什么?
帮我解决这个问题...
答案 0 :(得分:1)
您将错误数据传递给邮件功能。转到http://php.net/manual/en/function.mail.php并阅读说明如何使用它的文档。
另请注意,它会返回一个布尔值,告诉您邮件尝试是否成功,至少是这样:
....
$success = mail(...);
if ($success) {
echo "<p>mail sent</p>";
} else {
echo "<p>error: mail was not sent.</p>";
}
这样你的代码就不会说是否发送了邮件。
至于你的大量数据:全部评论。然后逐步取消注释位,直到它中断。您现在已经发现了问题,可以通过查看您提供的不喜欢的mail()函数来解决问题。