send form result as email attachment

Discussion in 'PHP' started by chspit, Dec 26, 2006.

  1. #1
    I am using php to process an html form, and the results entered in the web page are then sent to my email. The question i have is how can i receive these resuls in the form of an attachment (such as txt, csv xml..), rather than as part of the email body?

    Below is the php code i have.

    --------

    <?php

    $msgtxt = $msgtxt . $_POST['FirstName'] . ',';
    $msgtxt = $msgtxt . $_POST['LastName'] . ',';
    $msgtxt = $msgtxt . $_POST['Email'] . ',';
    $msgtxt = $msgtxt . $_POST['Title'] . ',';
    $msgtxt = $msgtxt . $_POST['Company'] . ',';
    $msgtxt = $msgtxt . $_POST['Phone'] . ',';
    $msgtxt = $msgtxt . $_POST['Country'] . ',';
    $msgtxt = $msgtxt . $_POST['Comments'] . ',';

    //Send Mail
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    mail("myemail@email.com", "Email heading", $msgtxt, $headers);

    ?>

    -------------------

    Thanks in advance for your reply. I wold appreciate if you show me an example.
     
    chspit, Dec 26, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try using PHPmailer, no need to reinvent the wheel.
     
    nico_swd, Dec 26, 2006 IP
  3. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #3
    fopen() a temp file with flag "w" for writing, fputs() the data, fclose() the file, add more to the headers in the mail() to include the attachment (Content-Disposition: attachment; filename= ... + mime type etc), then send and delete the file.
     
    legend2, Dec 26, 2006 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Barti1987, Dec 26, 2006 IP
  5. pixel_perfect

    pixel_perfect Banned

    Messages:
    238
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    this how to attache a file,
     
    pixel_perfect, Dec 26, 2006 IP