Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Mail Attachment

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    154
    Thanks
    52
    Thanked 0 Times in 0 Posts

    Mail Attachment

    I'm looking to send a file on my server called 'Spreadsheet.xls' as an attachment in php mail.

    PHP Code:
    include "../templates/email_body.php";


    $email_headers "From: tom@xyz.com\r\n";
    $email_headers .= "BCC: joe@xyz.com\r\n";
    $email_headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";
    mail("$customer_email","Sending Attachment",$email_message,$email_headers); 
    The file Spreadsheet.xls is in the same folder as this php file.

    I've had a look around on google and it seems a lot harder to do than it should!? Most the articles are about uploading a document to be sent by email, but I already have the file to send...?

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    i just googled php mail sending attachment and found several examples. you might try that, i have never done the attatchment deal myself but the examples are fairly clear.

  • #3
    Regular Coder
    Join Date
    Jan 2007
    Posts
    154
    Thanks
    52
    Thanked 0 Times in 0 Posts
    Thanks, the examples found explain how to send an attached file that has been uploaded. I just want the code to send a file from my server. The only one I could find that looked close was one about sending a zip file, but there was a lot of extra coding for compression

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    well maybe we both can learn something here.

    have you seen this

    http://www.finalwebsites.com/forums/...achment-script

    i was looking at this line, im not sure if thats all you need or not

    PHP Code:

    $header 
    .= "Content-Disposition: attachment;filename=\"".$filename."\"\r\n\r\n"

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,295
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Try using phpmailer. It makes life incredibly easy for sending emails, html emails, emails with attachments etc.

    The only problem with it you might run into is on line 1471 where I had to change the php version from 6 to 5 (and then a few lines below) to stop php moaning about deprecated functions (magic quotes).
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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