Send attachement with mail()?

Discussion in 'PHP' started by bobby9101, Jun 27, 2007.

  1. #1
    Hi, I would like to send a blank email with an image attchment, but I can't figure out how to send an attachment.
     
    bobby9101, Jun 27, 2007 IP
  2. woods

    woods Peon

    Messages:
    228
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Manually adding attachments on the mail() function will require you to read the contents and encode it to base64

    So it looks somewhat like this:
    Content-Transfer-Encoding: base64\n
    Content-Type: application/zip; name="test_file.zip"\n
    \n
    BASE64 ENCODED DATA HERE
    Code (markup):
    http://www.php.net/function.mail (pretty much always useful comments at php.net for whatever you're trying to do with a function, just scroll down.) There's some examples there :)

    If you don't have time for to bother about that I'd recommend using PHPMailer (phpmailer.sourceforge.net) instead which is much easier, example:

    <?php
          require("class.phpmailer.php");
          $mail = new phpmailer();
          $mail->From = 'me@mydomain.com';
          $mail->FromName = "My Site's Name";
          $mail->Subject = 'Email Subject';
          $mail->Body = "Here you can enter the body text for the email.
          In fact it can:
          >Span
          >Multiple Lines just like that!";
           
          $mail->AddAddress("joe@brown.com","Joe Brown");
          $mail->AddAttachment("./picture.jpg");
          $mail->AddAttachment("./picture2.jpg");
          $mail->Send();
          ?>
    
    
    PHP:
     
    woods, Jun 27, 2007 IP