weiner769 Posted February 8, 2010 Share Posted February 8, 2010 I have a form on my website that needs to send both text information and files. I have tried for the past week to get the php right and it does not seem to want to cooperate lol my php script is as follows: <?php $to= '[email protected]'; $subject= 'Application'; $from= 'Website'; $fname = $_POST['fname'] ; $lname = $_POST['lname'] ; $phone = $_POST['phone'] ; $email = $_POST['email'] ; $state = $_POST['state'] ; $city = $_POST['city'] ; $about = $_POST['about'] ; $experience = $_POST['experience'] ; $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $fname"; if (is_uploaded_file($fileatt)) { $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $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}\""; $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"; $data = chunk_split(base64_encode($data)); $message .= "--{$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"; } $body= stripslashes ('fname ' . $fname . ' lname ' . $lname . ' phone ' . $phone . ' email ' . $email . ' state ' . $state . ' city ' . $city . ' about ' . $about . ' experience ' . $experience . $from) ; $ok= mail( $to, $subject, $message, $headers, $body); if ($ok) { echo "<p>Form temporarily unavaliable</p>"; } else { echo "<p>Mail could not be sent. Sorry!</p>"; } ?><title>sendmail.php</title> I would prefer to send multiple files as attachments, but nowhere have I seen that that is possible. I really appreciate your time, thanks! Link to comment https://forums.phpfreaks.com/topic/191425-help-making-mailing-both-form-content-and-file/ Share on other sites More sharing options...
WolfRage Posted February 9, 2010 Share Posted February 9, 2010 http://www.php.net/manual/en/function.mail.php#83491 Link to comment https://forums.phpfreaks.com/topic/191425-help-making-mailing-both-form-content-and-file/#findComment-1009361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.