简体   繁体   中英

Email is not sending using php

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>\r\n";
   $headers  .= "MIME-Version: 1.0\r\n";
   $headers  .= "Content-Type: multipart/mixed; ";
   $headers  .= "boundary=".$num."\r\n";
   $headers  .= "--$num\r\n";

// This two steps to help avoid spam

       $headers .= "Message-ID: <".gettimeofday()."     TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
      $headers .= "X-Mailer: PHP v".phpversion()."\r\n";

// With message

   $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
   $headers .= "Content-Transfer-Encoding: 8bit\r\n";
   $headers .= "".$message."\n";
   $headers .= "--".$num."\n";

// Attachment headers

   $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."--";

// 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...

You're passing bad data to the mail function. Head over to http://php.net/manual/en/function.mail.php and read the documentation that tells you how to use it.

Also note that it returns a boolean value that tells you whether your attempt to mail was successful so at the very least:

....
$success = mail(...);
if ($success) {
  echo "<p>mail sent</p>";
} else {
  echo "<p>error: mail was not sent.</p>";
}

so that your code isn't lying about whether it sent the mail or not.

As for your massive amount of data: comment it all off. Then progressive uncomment bits until it breaks. You have now found the problem and can solve it by looking at what you're giving the mail() function that it doesn't like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM