Hi, As the subject says i am implementing the file upload field in my current form. first i have successfully added the code in my html webpage to get the file upload box. The next thing is bit complicated for me as i am the php guy and i tried but cannot able to go well. Here is the current code of my contact form which work pretty well without file upload and have js validation. <?php ob_start(); $fromemail="No-Reply "; // change here if you want $toemail="info@xyz.com"; // change here if you want $sub="XXXX feeback"; // change here if you want $success_page_name="thanks.html"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3'])); $fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4'])); $fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5'])); $contentmsg=stripslashes("<br><b><font style=color:#CC3300>$sub</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Name *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_1</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Email *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_2</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>City *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_3</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Phone *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_4</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Message *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_5</td> </tr> </table> "); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; @mail($toemail,$sub,$contentmsg,$headers); header("Location:$success_page_name"); } ?> PHP: and the file upload code which i found at w3school.com which will save the uploaded file to server here. <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> PHP: I would like to merge them so that the uploaded file will get in mail attached form with my current web form. Thanks in Advance.
I suggest you to find php mailing library which can send mails with attachments,for example zend_mail can do this. http://framework.zend.com/manual/en/zend.mail.attachments.html
Your code won't send an attachment at all - there's more code to it than that (I stopped analyzing it when I saw that you're missing the MIME boundary). See http://www.emanueleferonato.com/2008/07/22/sending-email-with-multiple-attachments-with-php/ for code that works. (The second "file" is your web form file.) Or you could send a single file by concatenating the uploaded file and the form data. Or you could send the uploaded file and include the form data as the message in the email.