0

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>
guybennet
  • 683
  • 1
  • 9
  • 25
  • One does not simply use `mail()` directly. You should consider a more robust/stable solution [swiftmailer](http://swiftmailer.org/). – HamZa Jul 15 '13 at 13:14
  • It might help if you told us what the error you're seeing is. – andrewsi Jul 15 '13 at 13:14
  • Unless you're not showing us your entire code, your first `$headers` should not start with a dot. You have `$headers .= "MIME-Version: 1.0\r\n";`. If that is in fact your first header, then remove the dot and replace with this `$headers = "MIME-Version: 1.0\r\n";`. (for one thing). Also, show us the code that is on line 59, also the lines before, and after it. – Funk Forty Niner Jul 15 '13 at 13:44
  • What is the reference to `$mailsonuc`? I only see it once in your posted code. You're obviously not showing us your entire code. – Funk Forty Niner Jul 15 '13 at 13:47
  • yeah there is 1 line before this code. it is: $headers = "From: Info Mail\r\n"; and line 59: $mailsonuc=mail($to, $subject, $message, $headers); – guybennet Jul 15 '13 at 14:11
  • @guybennet You haven't defined the `$to` variable, that's probably why you're getting errors. – Funk Forty Niner Jul 15 '13 at 15:25
  • @guybennet You say line 59 is `$mailsonuc=mail($to, $subject, $message, $headers);` yet your code reads as `$mailsonuc = mail("$r_email","$subject","$msg", $headers);`. **Which one is it?** **Change** `$mailsonuc=mail($to, $subject, $message, $headers);` **to** `$mailsonuc = mail("$r_email","$subject","$msg", $headers);`, try it and get back to me. – Funk Forty Niner Jul 15 '13 at 15:28
  • @guybennet Or, add/define `$to` such as `$to = your_email@your_site.com;` – Funk Forty Niner Jul 15 '13 at 15:30
  • 1
    @guybennet another thing. I'm not going to continue re-checking this thread. If you're going to reply to my comments, add the **@** symbol including my name. I.e. **@Fred**. – Funk Forty Niner Jul 15 '13 at 15:36
  • @Fred now it sends mail but you cant open file. it sends same name and size. i think its broken – guybennet Jul 16 '13 at 12:53
  • @guybennet What do you mean by *"it can't open the file and it sends same name and size"*? What are you trying to achieve; what are your expected results? – Funk Forty Niner Jul 16 '13 at 14:11
  • @Fred The e-mail was sent with an attached ,but the attachment gets corrupted. you cant open file. – guybennet Jul 16 '13 at 15:01
  • @guybennet Sorry, but that's not a topic which I know much about. I suggest you post another question about it. – Funk Forty Niner Jul 16 '13 at 15:14

2 Answers2

0

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

Community
  • 1
  • 1
VIVEK-MDU
  • 2,483
  • 3
  • 36
  • 63
0

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

barnamah
  • 39
  • 4
  • 9