SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending Attachment not working

    Hello all,

    I want to send an attachment through php using php mail() function.
    But my problem is I can see the attachment in my inbox but the message I have specified in $body variable is not displaying.
    Could anyone suggest me what i am doing wrong in the following code?

    PHP Code:
    $from "email1@gmail.com";
    $to "email2@gmail.com";
    $subject "Test mail with an attachment";

    $file_name "testpage.doc";
    $body "This is a test message.This is to show how to send the attachments using simple mail() function.\n\n";
    $boundary md5(time());
    $headers .= "From:".$from."\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";

    $message .= "--".$boundary."\n";
    $message .= "Content-Type: application/msword; name=\"".$file_name."\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n\n";
    $message .= "--".$boundary."\n";
    $message .= "--".$boundary."\n";
    $message .= $body;

    if(!
    mail($to$subject$message$headers))
        echo 
    "Mail Sending Failed";
    else
        echo 
    "Mail Sent"
    Your help will be highly appriciated.
    Thanks,
    Barbara

  2. #2
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this :

    PHP Code:
    $message .= "--".$boundary."\n"
    To this:
    PHP Code:
    $message "--".$boundary."\n"
    Try it and let me know what happened.

  3. #3
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for reply.I tried as you told me.
    But now no attachment + no message at all.
    PHP Code:
    //$message .= "--".$boundary."\n"; commented
    $message "--".$boundary."\n";
    $message .= $body
    Please guide me in my code.
    Barbara

  4. #4
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers . Solved.
    PHP Code:
    $from "email1@gmail.com";
    $to "email2@gmail.com";
    $subject "Test mail with an attachment";
    $file_name "testpage.doc";
    $body "This is a test message.\nThis is to show how to send the attachments using simple mail() function.\n";
    $boundary md5(time());
    $headers .= "From:".$from."\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
    $message .= "--".$boundary."\n";
    $message .= "Content-Type: application/msword; name=\"".$file_name."\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n\n";
    $message .= "--$boundary\n";

    $message .= "--".$boundary."\n";
    $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: binary\n\n";
    $message .= $body;
    $message .= "--$boundary\n";

    if(!
    mail($to$subject$message$headers))
        echo 
    "Mail Sending Failed";
    else
        echo 
    "Mail Sent"
    Now getting attachment and message also.
    Barbara


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •