The below PHP example helps you to send an email with multiple attachment file.
sendmail.html
sendmail.php
sendmail.html
<table width="90%" border="0" cellpadding="0" cellspacing="0" > |
<tr><td align= "center" valign= "top" > </td></tr> |
<tr> |
<td align= "center" valign= "top" ><form action= "sendmail.php" method= "post" name= "rfqfrm" id= "rfqfrm" enctype= "multipart/form-data" > |
<table width= "500" border= "0" cellspacing= "0" cellpadding= "6" > |
<tr> |
<td width= "150" align= "right" valign= "middle" >* First Name:</td> |
<td align= "left" valign= "middle" ><input name= "name" type= "text" id= "name" size= "25" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >* Last Name: </td> |
<td align= "left" valign= "middle" ><input name= "lastname" type= "text" id= "lastname" size= "25" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >* Email:</td> |
<td align= "left" valign= "middle" ><input name= "email" type= "text" id= "email" size= "30" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Company Name: </td> |
<td align= "left" valign= "middle" ><input name= "cmname" type= "text" id= "cmname" size= "15" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Address:</td> |
<td align= "left" valign= "middle" ><input name= "add" type= "text" id= "add" size= "35" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >City:</td> |
<td align= "left" valign= "middle" ><input name= "city" type= "text" id= "city" size= "30" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >State:</td> |
<td align= "left" valign= "middle" ><table width= "300" border= "0" cellspacing= "0" cellpadding= "0" > |
<tr> |
<td width= "50" ><input name= "state" type= "text" id= "state" size= "2" ></td> |
<td width= "50" align= "right" >Zip: </td> |
<td width= "200" ><input name= "zip" type= "text" id= "zip" size= "10" ></td> |
</tr> |
</table></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Phone:</td> |
<td align= "left" valign= "middle" ><input name= "phone" type= "text" id= "phone" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Fax:</td> |
<td align= "left" valign= "middle" ><input name= "fax" type= "text" id= "fax" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Attach File1:</td> |
<td align= "left" valign= "middle" ><input type= "file" name= "attachFile" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Attach File2:</td> |
<td align= "left" valign= "middle" ><input type= "file" name= "attachFile2" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Attach File3:</td> |
<td align= "left" valign= "middle" ><input type= "file" name= "attachFile3" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "middle" >Attach File4:</td> |
<td align= "left" valign= "middle" ><input type= "file" name= "attachFile4" ></td> |
</tr> |
<tr> |
<td align= "right" valign= "middle" >Attach File5:</td> |
<td align= "left" valign= "middle" ><input type= "file" name= "attachFile5" ></td> |
</tr> |
<tr> |
<td width= "150" align= "right" valign= "top" >* Please describe your project needs: </td> |
<td align= "left" valign= "middle" ><textarea name= "comments" cols= "30" rows= "7" id= "comments" ></textarea></td> |
</tr> |
<tr> |
<td align= "right" valign= "middle" > </td> |
<td align= "left" valign= "middle" ><input type= "reset" name= "Reset" value= "Clear" > |
<input type= "submit" name= "Submit2" value= "Submit" ></td> |
</tr> |
</table> |
</form></td> |
</tr> |
</table> |
<?php
$to = "emailaddress@gmail.com" ; |
$subject = "Request For Quote from Latva" ; |
$todayis = date ( "l, F j, Y, g:i a" ) ;
|
$message = " |
Date ------- $todayis |
Name ------ $name |
Last Name ------- $lastname |
Email ----------- $email |
Company --------- $cmname |
Address --------- $add |
City ------------ $city |
State ----------- $state |
Zip ------------- $zip |
Phone ----------- $phone |
Fax ------------- $fax |
Message --------- $comments |
"; |
$mime_boundary = "==Multipart_Boundary_x" .md5(mt_rand()). "x" ; |
$headers = "From: $email\r\n" . |
"MIME-Version: 1.0\r\n" . |
"Content-Type: multipart/mixed;\r\n" . |
" boundary=\"{$mime_boundary}\"" ; |
$message = "This is a multi-part message in MIME format.\n\n" . |
"--{$mime_boundary}\n" . |
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" . |
"Content-Transfer-Encoding: 7bit\n\n" . |
$message . "\n\n" ; |
foreach ( $_FILES as $userfile ) |
{ |
$tmp_name = $userfile [ 'tmp_name' ]; |
$type = $userfile [ 'type' ]; |
$name = $userfile [ 'name' ]; |
$size = $userfile [ 'size' ]; |
if ( file_exists ( $tmp_name )) |
{ |
if ( is_uploaded_file ( $tmp_name )) |
{ |
$file = fopen ( $tmp_name , 'rb' ); |
$data = fread ( $file , filesize ( $tmp_name )); |
fclose( $file ); |
$data = chunk_split ( base64_encode ( $data )); |
} |
$message .= "--{$mime_boundary}\n" . |
"Content-Type: {$type};\n" . |
" name=\"{$name}\"\n" . |
"Content-Disposition: attachment;\n" . |
" filename=\"{$fileatt_name}\"\n" . |
"Content-Transfer-Encoding: base64\n\n" . |
$data . "\n\n" ; |
} |
} |
$message .= "--{$mime_boundary}--\n" ; |
if (mail( $to , $subject , $message , $headers )) |
echo "Mail sent successfully." ; |
else |
echo "Error in mail" ; |
?>
not working on my website
ReplyDeletehello brother
ReplyDeleteplease add little bit code it's working fine
--------------------------- adding code -------------
$to = "ravi.city@gmail.com";
$subject= "Request For Quote from WWW.JEEVANMUKTI.INF0";
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$cmname = $_POST['cmname'];
$add = $_POST['add'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$comments = $_POST['comments'];
- - - - - - - - - - - - - - end ------------
------------full code ------it's working nice ------please check it
enjoy
Hi Ravindra ,
DeletePlease check this. i am getting error.
Hi
Delete-----------------
please try this code it is working for me.
-----------------------------
$todayis = date("l, F j, Y, g:i a") ;
$name = $_REQUEST["name"];
$lastname = $_REQUEST["lastname"];
$email = $_REQUEST["email"];
$cmname = $_REQUEST["cmname"];
$add = $_REQUEST["add"];
$city = $_REQUEST["city"];
$state = $_REQUEST["state"];
$zip = $_REQUEST["zip"];
$phone = $_REQUEST["phone"];
$fax = $_REQUEST["fax"];
$comments = $_REQUEST["comments"];
$message = "
Date : $todayis
Name : $name
Last Name : $lastname
Email : $email
Company : $cmname
Address : $add
City : $city
State : $state
Zip : $zip
Phone : $phone
Fax : $fax
Message : $comments
";
Great, thank you for the script!
ReplyDeleteHow Can I set a size limitation and specify the type of files to upload. eg. only jpeg and pdf
ReplyDeleteAwesome tutorial
ReplyDeleteThanks
really superrrrrrrrrrrrrr
ReplyDeleteHi check this here is much better running code .. http://phpsollutions.blogspot.com/2014/02/send-multiple-attachment-in-mail-using.html
ReplyDeleteHey there,
DeleteAs I am using this php form script, there's still options I'd like to add with his code:
select data-placeholder="Select Multiple Items" class="chosen-select" multiple>
option >Item 1/option
option>Item 2/option
option>Item 3/option
option>Item 4/option
/select
How can I get these options integrate into that php form, please?
This doesn't work:
option name="keywords3" type="text" id="keywords3" >Item 1 /option
option name="keywords4" type="text" id="keywords4" >Item 2 /option
Thanks.
I got this error after i hit the submit button. any idea why? i upload the sendmail.php file in php folder & sendmail.html. thanks a mill!! "The requested URL /sendmail.php was not found on this server."
ReplyDeleteit works great that code, the one who wrote it thanks so much a lot !!,
ReplyDeleteGreat dude...thanks
ReplyDeletethnx dear
ReplyDeleteAttachment is sending except data but why? where is the problem?
ReplyDeletecode working....... thank you.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletepleas sir can you send the the complit code the forms in html varables and the php script please sir
ReplyDeletenot working
ReplyDeletetext/x-generic error_log
ASCII text
[15-Apr-2016 00:37:35 Etc/GMT] PHP Notice: Undefined variable: fileatt_name in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 46
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: name in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 6
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: lastname in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 7
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: email in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 8
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: cmname in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 9
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: add in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 10
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: city in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 11
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: state in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 12
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: zip in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 13
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: phone in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 14
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: fax in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 15
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: comments in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 16
[15-Apr-2016 00:41:56 Etc/GMT] PHP Notice: Undefined index: attachment in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 17
[15-Apr-2016 00:42:40 Etc/GMT] PHP Notice: Undefined index: attachment in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 17
[15-Apr-2016 00:46:59 Etc/GMT] PHP Notice: Undefined index: attachment in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 17
[15-Apr-2016 00:49:34 Etc/GMT] PHP Notice: Undefined index: attachment in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 17
[15-Apr-2016 00:53:06 Etc/GMT] PHP Notice: Undefined index: attachment in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 17
[15-Apr-2016 00:54:03 Etc/GMT] PHP Notice: Undefined index: attachment in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 17
[15-Apr-2016 00:57:17 Etc/GMT] PHP Notice: Undefined variable: fileatt_name in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 58
[15-Apr-2016 00:57:38 Etc/GMT] PHP Notice: Undefined variable: fileatt_name in /home/ktkdexpg/public_html/citep.in/mail/sendmail.php on line 58
Kindly add below content in sendmail.php file
Delete$to = "your mail@gmail.com";
$subject= "Request For Quote from WWW.JEEVANMUKTI.INF0";
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$cmname = $_POST['cmname'];
$add = $_POST['add'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$comments = $_POST['comments'];
thousands thanks. It works perfect. very good job.
ReplyDeletethanks thanks thanks alot u don't know Your Artical is V.harmfully for me thanks again alot
ReplyDeleteHey there,
ReplyDeleteAs I am using this php form script, there's still options I'd like to add with his code:
select data-placeholder="Select Multiple Items" class="chosen-select" multiple>
option >Item 1/option
option>Item 2/option
option>Item 3/option
option>Item 4/option
/select
How can I get these options integrate into that php form, please?
This doesn't work:
option name="keywords3" type="text" id="keywords3" >Item 1 /option
option name="keywords4" type="text" id="keywords4" >Item 2 /option
Thanks.
" filename=\"{$fileatt_name}\"\n" . pls define this
ReplyDeleteThank you Bhava...1 number
ReplyDeleteIt is very informative blog.Thanks for sharing this blog. We have got so much information.
ReplyDeleteGmail Email Attachment Downloader
I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
ReplyDeleteHYIP Script