html - Send a message and upload a file in PHP -
this question has answer here:
- how upload & save files desired name 6 answers
i have form allows users send me message on email, want when user fills form , chooses file file gets uploaded server , message gets sent me. did message part couldn't file uploaded. here code: index page:
<form action="mail.php" method="post" enctype='multipart/form-data'> <input type="text" class="feedback-input" id="firstname" name="firstname" placeholder="first name" size="30" required=""> <br/> <input type="text" class="feedback-input" id="lastname" name="lastname" placeholder="last name" size="30" required=""> <br/> <input type="email" class="feedback-input" id="title" name="title" placeholder="e-mail" size="30" required=""> <br/> <textarea name="message" class="feedback-input" placeholder="what can with?" style="height: 150px;" required=""></textarea><br/> <br/> <input type="file" name="file" id="file" placeholder=" " tabindex="1" required/><br/> <input type="submit" name="submit" id="submit" value="send">
and mail.php file:
<?php $firstname = $_post['firstname']; $title = $_post['title']; $lastname = $_post['lastname']; $message = $_post['message']; $ip = $_server['remote_addr']; $formcontent=" from: $firstname $lastname \n email address: $title \n ip: $ip \n\n description : $message"; $recipient = "myemail@yahoo.com"; $subject = "new message!!"; $mailheader = "from: $title \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("error!"); header("location: www.mythankyoupage.com"); die(); ?>
i think file upload should based on http://www.w3schools.com/php/php_file_upload.asp please comment if stuck somewhere , i'll gladly help! :)
Comments
Post a Comment