PHPMailer Issues w/ AddAttachment

Discussion in 'PHP' started by unghosted, Aug 9, 2011.

  1. #1
    Ok, so it's my first time trying to send attachments through PHP and I decided to try it with PHPMailer.

    I'm trying to attach an excel .xls file to the email, but what it sends is a garbled version of the file. Plus, the HTML body displays perfectly if I don't add an attachment, but once I do, nothing else shows shows up on the email except the (garbled) attachment.


    Here's the send code:

    $mail = new phpmailer;
    $mail->IsMail();
    $mail->From = $from_email;
    $mail->FromName = $from_name;
    $mail->AddAddress($to_email);
    $mail->AddReplyTo($reply_email, $reply_name;
    $mail->AddAttachment("temp.xls", "order.xml", "quoted-printable", "application/vnd.ms-excel");
    $mail->IsHTML(true);
    $mail->Subject = $subject;
    $mail->Body = $html_body;
    $mail->Send();

    I've tried tinkering with the AddAttachment parameters, the phpmailer class itself, and nothing works.

    Hopefully, someone can point me in the right direction here.

    Thanks, in advance, for any help you can offer.
     
    unghosted, Aug 9, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    EricBruggema, Aug 24, 2011 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    Read the PHP manual page (at php.net) about mail(). Attaching a file isn't as easy as adding a header. (There are examples of how to do it, but you have to add a boundary at the top and bottom and read the file into the stream.)
     
    Rukbat, Aug 24, 2011 IP