Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,918 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,759 people online right now. Registration is fast and FREE... Join Now!




Upload files to a form then submit to e-mail address

 
Reply to this topicStart new topic

Upload files to a form then submit to e-mail address

van01
24 Mar, 2008 - 11:15 AM
Post #1

New D.I.C Head
*

Joined: 17 Jan, 2008
Posts: 3

Hi
Can some one please help me. I have created a form called UploadDoc. In this form I have a browse button to allow user to select the file to upload. I then use a php form called ThankYouDoc.php to send the form to my e-mail. This form and php code works when the user clicks on the sumbit button on the form. I would like to know how can I send the browsed file as an attachemt to my e-mail address. As at the moment only other fileds on the form are submitted to my e-mail address.


PHP Code for ThankYouDoc
CODE

<?PHP
$mailto = "consultant@i-angel.co.uk";
$email = $HTTP_POST_VARS['email'];
if ($email == "") {
$email = $mailto;
}
$mailsubj = "Upload Doc";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form :\n";

while (list ($key, $val) = each ($HTTP_POST_VARS))
{
if ($key!="submit")
{
$mailbody .= "$key : $val\n";
}
}
mail($mailto, $mailsubj, $mailbody, $mailhead);

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Upload Files To A Form Then Submit To E-mail Address
24 Mar, 2008 - 10:07 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,495



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Have you had a look at the following PHP tutorials?

http://www.dreamincode.net/forums/showtopic9797.htm
http://www.dreamincode.net/forums/showtopic36108.htm
http://www.dreamincode.net/forums/showtopic10130.htm
User is online!Profile CardPM
+Quote Post

van01
RE: Upload Files To A Form Then Submit To E-mail Address
25 Mar, 2008 - 05:26 AM
Post #3

New D.I.C Head
*

Joined: 17 Jan, 2008
Posts: 3

Hi

Thanks for those links. I have added to the code to upload the browsed file and attach it to the e-mail address when the user submits the form. I have one problem now. The e-mail function has stopped working. I see the page when I click on the submit button but receive no e-mail. Could you please check the code for me please? I would appreciate you help Thanks. Code below also attached the page.

<?PHP
$mailto = "consultant@i-angel.co.uk";
$email = $HTTP_POST_VARS['email'];
if ($email == "") {
$email = $mailto;
}
$mailsubj = "Upload CV";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form :\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
if ($key!="submit")
{
$mailbody .= "$key : $val\n";


#$mailhead = "From: $email\n";
$UploadCV =$_FILES['UploadCV'];
$UploadCV_path =$_FILES['UploadCV']['tmp_name'];
$UploadCV_name =$_FILES['UploadCV']['name'];
$UploadCV_size =$_FILES['UploadCV']['size'];
$UploadCV_type =$_FILES['UploadCV']['type'];

$fp =fopen ($UploadCV_path, "rb");
$file = fread( $fp, $UploadCV_size);
fclose ($fp);

$num =md5(time());
$str = "==Multipart_Boundary_x{$num}x";

$file =chunk_split(base64_encode($file));

$hdr ="MIME-Version: 1.0\r\n";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "boundary=\"{$str}\"\r\n";


$msg ="This is a multi-part message in MIME format\r\n\n";
$msg .="--{$str}\r\n";
$msg .="Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "--{$str}\r\n";

$msg .="Content-Type: {$UploadCV_typr}; ";
$msg .= "name=\"{$UploadCV_name}\"\r\n";
$msg .= "Content-Disposition: attachment; ";
$msg .= "filename=\"{$UploadCV}\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .="$file\r\n\n";
$msg .= "--{$str}";
}

}
mail($mailto, $mailsubj, $mailbody, $mailhead, $msg, $hdr);
?>


Attached File(s)
Attached File  ThankYouCV.php ( 12.96k ) Number of downloads: 58
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:09PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month