how to send email with attachment(.doc files) using php -
i have been struggling add attachment mail using thank you.php. generraly resume/cv subnission form.. here job application.php code:
<form name="frm" action="thankyou.php" method="post" style="padding-top:10px;"> <table style="text-align: left; width: 100%; color: rgb(255, 0, 0); font-family: arial; font-size: 11px; font-weight: bold;" rules="all" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td>*mandatory fields</td> </tr> <tr> <td align="left" valign="top"><p><table id="table2" cellspacing="0" cellpadding="3" width="100%" align="center" border="0"> <tr> <td style="width: 152px; height: 31px" valign="top" align="left"><span id="label1" class="text" class="text" style="background-color:transparent;"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><span id="label15" class="asterix" style="color:red;"></span>form of address</span></span></td> <td style="height: 31px"><select name="ddtitle" id="ddtitle" class="formtext"> </select></td> </tr><br> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><font color="#ff0000"><sup>*</sup></font>first name:<font color="#ff0000"></font></span></td><br> <td valign="top"><input type="text" size="35" name="name" id="name" value=""></td></tr> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><font color="#ff0000"><sup>*</sup></font>last name:<font color="#ff0000"></font></span></td> <td valign="top"><input type="text" size="35" name="lname" id="lname" value=""></td></tr><br> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000">address: <font color="#ff0000"></font></span></td> <td valign="top"><textarea cols="28" rows="2" name="address" id="address"></textarea><br><br> <span id="txt_mobile" style="font-size:11px;"></span></td> </tr> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><font color="#ff0000"><sup>*</sup></font>city:<font color="#ff0000"></font></span></td> <td valign="top"><input type="text" size="35" name="city" id="city" value=""></td></tr><br> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><font color="#ff0000"><sup>*</sup></font>contact no:<font color="#ff0000"></font></span></td> <td valign="top"><input type="text" size="35" name="number" id="number" value=""></td></tr><br> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><font color="#ff0000"><sup>*</sup></font>email id:<font color="#ff0000"></font></span></td> <td valign="top"><input type="text" size="35" name="email" id="email" value=""></td></tr><br> <tr> <td height="35" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000"><font color="#ff0000"><sup>*</sup></font>position applied for:<font color="#ff0000"></font></span></td> <td style="height: 21px"><select name="position" id="position" class="formtext"> </select> </td></tr><br> <tr> <td style="width: 152px" valign="top"><span id="label4" class="text" class="text"> <span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000">current organisation</span></span></td> <td><input type="text" size="35" name="organization" id="organization" value=""></td> </tr><br> <tr> <td style="width: 152px; height: 43px" valign="top"><span id="label5" class="text" class="text"> <span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000">designation</span></span></td> <td style="height: 43px"><input type="text" size="35" name="designation" id="designation" value=""></td> </tr><br> <tr> <td style="width: 152px; height: 23px" valign="top"><span lang="en-gb" style="font-family: 'times new roman'; font-size: 11pt; mso-fareast-font-family: 'times new roman'; mso-ansi-language: en-gb; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><span id="label32" class="text" class="text"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000">total work experience </span></span></span></td> <td><select name="experienceyears" id="experienceyears" class="formtext"> </select><select name="experienceyears" id="experiencemonths" class="formtext"> </select></td> </tr><br> <tr> <td valign="top" width="100%" colspan="2"> <table id="table11" cellspacing="0" cellpadding="1" width="100%" border="0"> <tr> <td class="text" style="height: 15px" valign="top"><span style="font-size:13px; font-family:arial; font-weight: normal; color:#000000">resume</span> </td> <td valign="top"><input name="file" type="file" id="file" class="formtext" /> </td> </tr><br> </table> </td> </tr> <!<tr> <td colspan="2"><span id="label13" class="text">enter text shown in box below</span></td> </tr> <tr> <td colspan="2"><img id="image1" src="../createcaptcha.aspx" style="border-width:0px;" /><input name="strcaptcha" type="text" maxlength="6" id="strcaptcha" class="formtext" style="width:112px;" /></td> </tr> <tr> <td align="center" colspan="2"><input style="margin-left:50px;" type="submit" value="submit" class="submit" onclick="return reguser_validation(frm);"/></td> </tr> <!-- instanceendeditable --> </table> </tr> </table> </td> </tr> <tbody> </table> </td> </tr></td></tr></table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> /* validation fields*/<br> <script type="text/javascript" src="email_validate.js"></script><br> <script type="text/javascript" src="signup.js"></script><br> <script language="javascript"><br> function reguser_validation(field) <br> {<br> var name = document.frm.name;<br> var lname = document.frm.lname;<br> var city = document.frm.city;<br> var number = document.frm.number;<br> var email = document.frm.email;<br> var position = document.frm.position;<br> if ((name.value == null) || (name.value == ''))<br> { alert("please enter first name"); <br> name.focus();<br> return false;<br> }<br> if ((lname.value == null) || (lname.value == ''))<br> { alert("please enter last name"); <br> lname.focus();<br> return false;<br> } if ((city.value == null) || (city.value == ''))<br> { alert("please enter city name"); <br> city.focus();<br> return false;<br> }<br> if ((number.value == null) || (number.value == ''))<br> { alert("please enter contact number"); <br> number.focus();<br> return false;<br> } if(mobile_validate(number) == false)<br> { return false;<br> }<br> if ((email.value == null) || (email.value == '')){<br> alert("please enter email id.");<br> email.focus();<br> return false;<br> }<br> if (emailcheck(email.value) == false){<br> alert("please enter valid email id.");<br> email.focus();<br> return false;<br> }<br> if (position.value == '')<br> { alert('please enter position applying for');<br> position.focus();<br> return false;<br> } <br> return true;<br> } <br>
here thank you.php:
<?php $to = "web@adisysonline.com";<br> $subject = "uploaded file";<br> $fileatt = $_files['file']['tmp_name'];<br> $fileatt_type = $_files['file']['type'];<br> $fileatt_name = $_files['file']['name'];<br> $headers = "from: $from";<br> if (is_uploaded_file($fileatt))<br> { // read file attached ('rb' = read binary)<br> $file = fopen($fileatt, 'rb');<br> $data = fread($file, filesize($fileatt));<br> $semi_rand = md5(time()); <br> $mime_boundary = "==multipart_boundary_x{$semi_rand}x"; <br> $headers .= "\nmime-version: 1.0\n" . "content-type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";<br> $mail_body = "this multi-part message in mime format.\n\n" . "--<br>{$mime_boundary}\n" . "content-type: text/html; charset=\"iso-8859-1\"\n" .<br> "content-transfer-encoding: 7bit\n\n" . $mail_body . "\n\n";<br> $data = chunk_split( base64_encode($data));<br> $mail_body .= "--{$mime_boundary}\n" . "content-type: {$fileatt_type};\n" . " <br>name=\"{$fileatt_name}\"\n" . "content-disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "content-transfer-encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; <br> if ($_server['request_method'] == "post") {<br> foreach ($_post $key => $value) { <br> $msg .= ucfirst ($key) ." : ". $value . "\n"; <br> }<br> }<br> else {<br> foreach ($_get $key => $value) { <br> $msg .= ucfirst ($key) ." : ". $value . "\n"; <br> }<br> } $ok = @mail($to, $subject, $msg, $mail_body, $headers);<br> if($ok)<br> echo "<b>thank submitting resume.<br> possible.</b>";<br> else<br> echo "server busy please try after few minutes";<br> fclose($file);<br> }<br> ?><br>
any apperciable...thank you...waiting expertise reply....
$file1=$_files['filenm']['name']; $to = "example@gmail.com"; $subject = "your subject"; $base = basename($file1); $file = fopen('your folder name/'.$file1,'rb'); $size = filesize('your folder name/'.$file1); $data = fread($file,$size); fclose($file); $data = chunk_split(base64_encode($data)); $message="<html><body>"; $message="<table border='1'>"; $message.="<tr><td colspan='3' align='center' style='color:#ffffff;font-size:large; background:#000000'>information</td></tr>"; $message.="</table>"; $message.="</body></html>"; //boundary $div = "==multipart_boundary_x".md5(time())."x"; //headers $head = "from: $email\n". "mime-version: 1.0\n". "content-type: multipart/mixed;\n". " boundary=\"$div\""; //message $mess = "--$div\n". "content-type: text/html; charset=\"iso-8859-1\"\n". "content-transfer-encoding: 7bit\n\n". "$message\n\n". "--$div\n". "content-type: application/octet-stream; name=\"$base\"\n". "content-description: $base\n". "content-disposition: attachment;\n". " filename=\"$base\"; size=$size;\n". "content-transfer-encoding: base64\n\n". "$data\n\n". "--$div\n"; $return = "-f$email"; mail($to,$subject,$mess,$head,$return);
try code used code send mail type of attachment
Comments
Post a Comment