简体   繁体   中英

Bad parameters to mail() function issue in php email

error: Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/19/10977719/html/turgut/email/send.php on line 59

i'm trying to send mail with attachments. it shows error.

it works without attachment but i dont need it.

this is not working, same error: http://www.vivekmoyal.in/send-email-attachment-in-php-send-attachment-in-email-php/

this is my php code:

    $upload_name=$_FILES["upload"]["name"];
    $upload_type=$_FILES["upload"]["type"];
    $upload_size=$_FILES["upload"]["size"];
    $upload_temp=$_FILES["upload"]["tmp_name"];

    $fp = fopen($upload_temp, "rb");
    $file = fread($fp, $upload_size);

    $file = chunk_split(base64_encode($file));
    $num = md5(time());     

$ad     = $_POST['ad'];   
$email  = $_POST['email'];
$r_email  = $_POST['r_email'];
$msg    = $_POST['msg'];
$subject    = $_POST['konu'];



       $headers  .= "MIME-Version: 1.0\r\n";
       $headers  .= "Content-Type: multipart/mixed; ";
       $headers  .= "boundary=".$num."\r\n";
       $headers  .= "--$num\r\n";

       // spamden kaçmak için bir yöntem

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

$mailsonuc = mail("$r_email","$subject","$msg", $headers); 

this is html:

<form id="attach" name="attach" action="gonder.php" method="post" enctype="multipart/form-data">
            <h1>{TOP_MSG}</h1>

            <table border="0" width="650">
    <tr>
        <td valign=middle>{NAME}</td>
        <td>:</td>
        <td><input type="text" placeholder="Adınız Soyadınız" required name="ad" /></td>
    </tr>
    <tr>
        <td valign=middle>{SENDER}</td>
        <td>:</td>
        <td><input type="text" placeholder="E-Posta Adresiniz" required name="email" /></td>
    </tr>
        <tr>
        <td valign=middle>{RECEIVER}</td>
        <td>:</td>
        <td><input type="text" placeholder="Alıcı E-Posta Adresi" required name="r_email" /></td>
    </tr>

    <tr>
        <td valign=middle>{KONU}</td>
        <td>:</td>
        <td><textarea name="konu"  required="" cols="46" rows="1"></textarea></td>
    </tr>
    <tr>
        <td valign=middle>{MESSAGE}</td>
        <td>:</td>
        <td><textarea name="msg"  required="" cols="46" rows="7"></textarea></td>
    </tr>
        <tr>
        <td valign=middle>{EK}</td>
        <td>:</td>
        <td> <input type="file" name="upload" id="upload"></td>
    </tr>

    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>        

            <div align="center">
                <input type="submit" value="Gönder" id="send" name="send" />
            </div>
        </form>

I think you issues based on minor mistake only.

  1. Check your PHP version
  2. Mail your hosting company and report it to them.
  3. Try removing the Bcc: Header's and see if that work's.

simply search result

Refer this link too:

This is example for fileupload

other wise, please don't build your own MIME emails. Use PHPMailer or Swiftmailer , which do almost everything for you. You can replace you entire script with about 5 or 6 lines of code. unless you can Refer this links also

I had the same issue and noticed that I had HTML character <p> in the subject line. Once removed, it worked.

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