SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    york
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Multipart Email Attachment Problem

    Hi,

    I'm having a bit of a nightmare getting a form to html email working properly.

    There are up to 5 uploads allowed by the form, although at the moment I'm only trying to process one until I get that working.

    Here's the the necessary code excerpts - the first part of the message works fine.

    PHP Code:
    $msg="<html><body><p>Some Text</p></body></html>";
    //unique ID for the email boundaries

    $uid=md5(uniqid(time()));
    $subject="Form Submitted Online";
    $headers="From: "."Joe Bloggs"." <"."joe@bloggs.co.uk".">\r\n";
    $headers.="Reply-To: ""joe@bloggs.co.uk" "\r\n";
    $headers.="MIME-Version: 1.0\r\n";
    $headers.="Content-Type: multipart/mixed; boundary=\"$uid\"";
    $bound="--".$uid."\r\n";
    $bound_last="--".$uid."--\r\n";

    //build the HTML message section
    $message.= "If you can see this MIME than your client doesn't accept MIME types!\r\n".$bound;  
    $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n".$msg.$bound;

    //Process the file uploads
    //This is working and copying successfully into the uploads directory

    $file=file_get_contents($path_of_uploaded_file);

    //headers for the email attachment
    $message.="Content-Type: ".'image/jpg'."; name=\"".$name_of_uploaded_file."\"\r\n";
    $message.="Content-Transfer-Encoding: base64\r\n";
    $message.="Content-Disposition: attachment; filename=".'"'.$name_of_uploaded_file.'"'."\r\n".chunk_split(base64_encode($file));
    $message.=$bound_last;

    mail ($recipient$subject$message$headers); 
    When I run the script the email comes through. The html bit is fine but is followed by the attachment contents in a huge chunk of ascii text underneath the html, rather than as a file attachment.

    I hope I'm doing something simple wrong but have been trying loads of tweaks from different tutorials, none of which are helping.

    In case it's relevant I'm on Outlook 2003 but have also checked via webmail and getting the same results.

    Many thanks in advance for any assistance.

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I just try out with a script from this site:

    http://www.emanueleferonato.com/2008...ents-with-php/

    and it tested fine.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    york
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the response. After a very pain-staking search for line breaks, white spaces and commas, I managed to get things working.


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
  •