Help with email attachments

Discussion in 'PHP' started by fisicx, May 7, 2007.

  1. #1
    I have built the form and got the processing scrip to work but am having a problem sending both a message and an attachment.

    The form works fine and returns all the variables in an echo statement when I submit but I can't work out how to send a message body. When I recieve an email from the form I get the sender, subject and attachment but how can I send the sender, subject, message and attachment.

    http://www.fisicx.com/formmail/attachment2.htm for the Html Form.

    http://www.fisicx.com/formmail/attachment2.txt for the PHP script (txt extension so you can download it).

    (Not got live links yet)

    What I want is to send the frame type and size in the message body and attach an image file. Where do I put the necessary code?

    Ta very much
     
    fisicx, May 7, 2007 IP
  2. RRWH

    RRWH Active Member

    Messages:
    821
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    70
    #2
    I had similar problems in the past.

    I have not read your code but I found the problem to be with the boundary declaration

    What I suggest you do is to ensure that within your email headers, your Boundary starts with ----= That is four dashes then equals.

    Now the Mime within the message each part should start with ------= SIX dashes and an equals.

    I just grabbed a RAW email that shows this

    
    MIME-Version: 1.0
    Content-Type: multipart/related;
            type="multipart/alternative";
            boundary="----=_NextPart_000_0014_01C791BF.6BC34990"
    X-Priority: 3
    X-MSMail-Priority: Normal
    X-Mailer: Microsoft Outlook Express 6.00.2462.4682
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.1081
    X-Spam-Exim: ThJ2qxCzY5dcl2FzdhlAx6is
    
    This is a multi-part message in MIME format.
    
    ------=_NextPart_000_0014_01C791BF.6BC34990
    Content-Type: multipart/alternative;
            boundary="----=_NextPart_001_0015_01C791BF.6BC34990"
    
    
    ------=_NextPart_001_0015_01C791BF.6BC34990
    Content-Type: text/plain;
    Code (markup):
     
    RRWH, May 8, 2007 IP
  3. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sending attachments can get pretty messy. If you are new to PHP you will have an easier time using a class that handles the messy details. PHPMailer is a good example:

    http://phpmailer.sourceforge.net/
     
    lemaitre, May 8, 2007 IP
  4. fisicx

    fisicx Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your replies, It was the MIME boundaries.

    I've changed the script:

    http://www.fisicx.com/formmail/uploader3.htm
    http://www.fisicx.com/formmail/uploader3.txt

    Works much better now, it's just the validation that doesn't do what it is suppsed to do. Ho hum.
     
    fisicx, May 8, 2007 IP
  5. RRWH

    RRWH Active Member

    Messages:
    821
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    70
    #5
    Yes, it took me several days to work out and correct the MIME boundaries myself. It is one thing that is not well documented anywhere and took a fair bit of digging to get there.

    you'll get there!
     
    RRWH, May 9, 2007 IP
  6. fisicx

    fisicx Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The joy of PHP. Still fairly new to the game so venturing out from HTML takes me well away from my comfort zone. Much prefer to stay within a mouse click of CSS, much more sensible than all those weird symbols on the top row of my keyboard.
     
    fisicx, May 9, 2007 IP