Solved

emailing file as attachement from form submission

Posted on 2004-10-22
181 Views
Last Modified: 2008-03-06
Hello.

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?

Thanks!


-------------------------------------------------------------------------
<?php
ob_start();
include("../lib/global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
$file2upload=$HTTP_POST_FILES["file2upload"];
if(!is_uploaded_file($HTTP_POST_FILES["file2upload"]["tmp_name"])){
$error.="<li>The file, ".$HTTP_POST_FILES["file2upload"]["name"].", was not uploaded!";
$errors=1;
}
if($errors==1) echo $error;
else{
$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("me@myemail.com","Form Submitted at your website",$message,"From: me@myemail.com");}
header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $relative_url);
ob_end_flush();
?>
-------------------------------------------------------------------------
0
Question by:hankknight
    2 Comments
     
    LVL 27

    Accepted Solution

    by:
    You are best advised to use a class to handle mime attachments sucj as the pear package: mail_mime
    http://pear.php.net/package/Mail_Mime

    Or better still let phpmailer handle everything for you:
    http://phpmailer.sourceforge.net/

    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.
    0
     
    LVL 27

    Expert Comment

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

    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