dsft8327 2013-09-19 21:26
浏览 28
已采纳

电子邮件不是使用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>
";
   $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...

  • 写回答

1条回答 默认 最新

  • dry9192 2013-09-19 21:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi