I am using the following code for sending attachments to the email...but i am unable to get the email..
I am able to get the message for successfully sending mail like " message sent " but the email is not going to corresponding mail id..
I don't where i do wrong....
Here is php file ...
<?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());
//Normal headers
$headers = "From: Info Mail<Info@example.com>
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."
";
$headers .= "--$num
";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">
";
$headers .= "X-Mailer: PHP v".phpversion()."
";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1
";
$headers .= "Content-Transfer-Encoding: 8bit
";
$headers .= "".$message."
";
$headers .= "--".$num."
";
// Attachment headers
$headers .= "Content-Type:".$upload_type." ";
$headers .= "name=\"".$upload_name."\"r
";
$headers .= "Content-Transfer-Encoding: base64
";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$upload_name."\"
";
$headers .= "".$file."
";
$headers .= "--".$num."--";
// SEND MAIL
mail($to, $subject, $message, $headers);
fclose($fp);
echo '<font style="color:#333333">Mail sent please check inbox and spam both <br /></font>';
}
}
?>
//HTML code for form details and adding attachment..
<form id="attach" name="attach" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>" enctype="multipart/form-data">
//Html code for mail details
</form>
I am getting "Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent...." and also it is showing the "Mail sent please check inbox and spam both ".. what's the problem ?
Help me to fix this problem...