html - send attachments and data in form in an email with php -
this php code
and html form below want data name , email, phone number fields , file attachment.
now tried file attached ( without other information entered) in live server environment getting , attachment in mail different format (like have send word doc word file in dat format doesn't display data in word file)
<?php if(isset($_post['submit'])) { //the form has been submitted, prep nice thank message $output = '<h1>thanks file , message!</h1>'; //set form flag no display (cheap way!) $flags = 'style="display:none;"'; //deal email $to = 'xxxx@gmail.com'; $subject = 'details , file attachments '; $message = strip_tags($_post['message']); $attachment = (file_get_contents($_files['file']['tmp_name'])); $filename = $_files['file']['name']; $boundary =md5(date('r', time())); $headers = "from: xxxxxx@gmail.com\r\nreply-to: xxxxxxx@gmail.com"; $headers .= "\r\nmime-version: 1.0\r\ncontent-type: multipart/mixed; boundary=\"_1_$boundary\""; $message="this multi-part message in mime format. --_1_$boundary content-type: multipart/alternative; boundary=\"_2_$boundary\" --_2_$boundary content-type: text/plain; charset=\"iso-8859-1\" content-transfer-encoding: 7bit $message --_2_$boundary-- --_1_$boundary content-type: application/octet-stream; name=\"$filename\" content-transfer-encoding: base64 content-disposition: attachment $attachment --_1_$boundary--"; mail($to, $subject, $message, $headers); } ?>
this html file suggest me how modify code getting values of other field email
<td height="12"> <?php echo $output; ?> <form enctype="multipart/form-data" action="<?php echo $_server['php_self'];?>" method="post" <?php echo $flags;?>> <fieldset> <legend>submit interest</legend> <p><label class="title" for="name">your name:</label> <input type="text" name="name" id="name"><br /></p> <p> <label class="title" for="email">your email:</label> <input type="text" name="email" id="email"></p> <p> <label class="title" for="phone">your phone:</label> <input type="number" name="phone" id="phone"></p> <p><label for="location" class="title">total experience :</label> <select name="location" id="location"> <option value="ny">1</option> <option value="il">2</option> <option value="ca">3+</option> </select></p> <span class="title">upload resume</span> <input type="file" name="resume" /> </p> </fieldset> <div><input type="submit" name="submit" id="submit" value="send"></div> </form></td>
content-transfer-encoding: base64
your headers saying data in base64
format, actual content raw binary. try using base64_encode($attachment)
before including body.
that said, please don't manually. library take care of has been mentioned in comments.
Comments
Post a Comment