emailing file as attachement from form submission

Posted on 2004-10-22
Last Modified: 2008-03-06

I use the following to process form submissions.
It uploads the file submitted to the server and sends a notice to the webmaster.

I don't want the file to be uploaded.  Instead, I want the file to be emailed to the webmaster as an attachement, along with the notice.

How can this be done?


$error="The following errors occured while processing your form input.<ul>";
$error.="<li>The file, ".$HTTP_POST_FILES["file2upload"]["name"].", was not uploaded!";
if($errors==1) echo $error;
$image_part = date("h_i_s")."_".$HTTP_POST_FILES["file2upload"]["name"];
$image_list[0] = $image_part;
copy($HTTP_POST_FILES["file2upload"]["tmp_name"], "files/".$image_part);
$message="file2upload: ".$where_form_is."files/".$image_list[0]."
$message = stripslashes($message);
@mail("","Form Submitted at your website",$message,"From:");}
header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $relative_url);
Question by:hankknight
    LVL 27

    Accepted Solution

    You are best advised to use a class to handle mime attachments sucj as the pear package: mail_mime

    Or better still let phpmailer handle everything for you:

    Then you can add an attachment as easy as: $mail->AddAttachment("/tmp/image.jpg", "new.jpg");

    For examples of use see the examples at the phpmailer site, its very straight forward.
    LVL 27

    Expert Comment

    Please see this thread for examples of use: http:Q_21141127.html
    if you need it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now