PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
php / mail / attachment Posted by Haile on 23 Apr 2008 at 2:21 AM
Hello,

I have a form and i set this data into a XML file.
Now i want to sent this file as attachment to my e-mail adres.

But how can i do this?

Regards en thanks,
Report
Re: php / mail / attachment Posted by tvienti on 23 Apr 2008 at 1:50 PM
: Hello,
:
: I have a form and i set this data into a XML file.
: Now i want to sent this file as attachment to my e-mail adres.
:
: But how can i do this?
:
: Regards en thanks,

I haven't tested this but it should get you on the right track. Google "php mail attachment" and you can probably find plenty of info.

function sendAttachment($to, $from, $subject, $message, $path_to_attachment, $filename, $MIME_type)
{
    /* do error checking here to make sure file exists, is readable, ... */
    $full_path = "$path_to_attachment/$filename";
    $size = filesize($full_path);
    $attachment = chunk_split(base64_encode(file_get_contents($full_path)));
    $boundary = uniqid();

    /* do input cleaning here to make sure nobody's attempting a header injection */

    /* send the message */
    $headers = array();
    $headers[] = "From: $from\n";
    $headers[] = "Content-Type: multipart/mixed; boundary=\"$uid\"\n\n";
    $headers[] = "This is a multi-part message in MIME format.\n";
    $headers[] = "--$boundary\n";
    $headers[] = "Content-Type: text/plain; charset=iso-8859-1\n";
    $headers[] = "Content-Transfer-Encoding: 7bit\n\n";
    $headers[] = "$message\r\n\r\n";
    $headers[] = "--$uid\n";
    $headers[] = "Content-Type: $MIME_type; name=\"$filename\"\n";
    $headers[] = "Content-Transfer-Encoding: base64\r\n";
    $headers[] = "Content-Disposition: attachment; filename=\"$filename\"\n\n";
    $headers[] = "$content\n\n";
    $headers[] = "--$uid--";
    $header = implode('', $headers);

    /* add pass/fail checks here too */    
    mail($to, $subject, "", $header);
}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.