How to attach a file to send a mail using php -
i have been struggling mail attachment using php .
below application form.php
<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"> <option value=" ">select</option> <option value="mr.">mr.</option> <option value="ms.">ms.</option> <option value="ms.">mrs.</option> </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> <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> <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> <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> <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> <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"> <option value="">select</option> <option value="trainee business development executive">trainee business development executive</option> <option value="business development executive">business development executive</option> </select> </td></tr> <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> <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> <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"> <option value=" ">years</option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> <option value="32">32</option> <option value="33">33</option> <option value="34">34</option> <option value="35">35</option> <option value="36">36</option> <option value="37">37</option> <option value="38">38</option> <option value="39">39</option> <option value="40">40</option> </select><select name="experienceyears" id="experiencemonths" class="formtext"> <option value=" ">months</option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> </select></td> </tr> <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> </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> /*validations*/ <script type="text/javascript" src="email_validate.js"></script> <script type="text/javascript" src="signup.js"></script> <script language="javascript"> function reguser_validation(field) { var name = document.frm.name; var lname = document.frm.lname; var city = document.frm.city; var number = document.frm.number; var email = document.frm.email; var position = document.frm.position; if ((name.value == null) || (name.value == '')) { alert("please enter first name"); name.focus(); return false; } /*if(name='!alphabetics') { alert("please enter alphabets in first name"); return false; }*/ if ((lname.value == null) || (lname.value == '')) { alert("please enter last name"); lname.focus(); return false; } /*if(lname='!alphabetics') { alert("please enter alphabets in last name"); return false; }*/ if ((city.value == null) || (city.value == '')) { alert("please enter city name"); city.focus(); return false; } /* if(city='!alphabetics') { alert("please enter alphabets in city name"); return false; }*/ if ((number.value == null) || (number.value == '')) { alert("please enter contact number"); number.focus(); return false; } if(mobile_validate(number) == false) { return false; } if ((email.value == null) || (email.value == '')){ alert("please enter email id."); email.focus(); return false; } if (emailcheck(email.value) == false){ alert("please enter valid email id."); email.focus(); return false; } if (position.value == '') { alert('please enter position applying for'); position.focus(); return false; } return true; } </script>
the below thankyou.php
<?php $to = "web@adisysonline.com"; $subject = "uploaded file"; $fileatt = $_files['file']['tmp_name']; $fileatt_type = $_files['file']['type']; $fileatt_name = $_files['file']['name']; $headers = "from: $from"; if (is_uploaded_file($fileatt)) { // read file attached ('rb' = read binary) $file = fopen($fileatt, 'rb'); $data = fread($file, filesize($fileatt)); $semi_rand = md5(time()); $mime_boundary = "==multipart_boundary_x{$semi_rand}x"; $headers .= "\nmime-version: 1.0\n" . "content-type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $mail_body = "this multi-part message in mime format.\n\n" . "--{$mime_boundary}\n" . "content-type: text/html; charset=\"iso-8859-1\"\n" . "content-transfer-encoding: 7bit\n\n" . $mail_body . "\n\n"; $data = chunk_split( base64_encode($data)); $mail_body .= "--{$mime_boundary}\n" . "content-type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "content-disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "content-transfer-encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if ($_server['request_method'] == "post") { foreach ($_post $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } else { foreach ($_get $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } $ok = @mail($to, $subject, $msg, $mail_body, $headers); if($ok) echo "<b>thank submitting resume.<br> possible.</b>"; else echo "server busy please try after few minutes"; fclose($file); } ?>
and need know how add virus checker attachment avoid virus
appreciable..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 change email, subject, message, , folder name
Comments
Post a Comment