Sassci Posted May 17, 2010 Share Posted May 17, 2010 I am completely new to PHP and I need some help trying to figure this out. I am trying to put together a script that will allow e-mails with attachments. I used a video tutorial and did all that was stated to do yet I am not having any luck. I have the Apache server thing installed and working on my computer so I can check this thing out...to no avail. If anyone can guide me in this I would greatly appreciate it. What I have done so far is listed below. Thankz... <?php if(isset($_POST) && !empty($_POST)) { if(!empty($_FILES['attachment']['name'])) { $file_name = $_FILES['attachment']['name']; $temp_name = $_FILES['attachment']['tmp_name']; $file_type = $_FILES['attachment']['type']; $base = basename($file_name); $extension = substr($base, strlen($base)-4, strlen($base)); $allowed_extensions = array(".doc","docx",".pdf",".png",".jpg"); if(in_array($extension,$allowed_extensions)) { $from = $_POST['email']; $to = "[email protected]"; // I have my contact email here $subject = "Test with attachment"; $message = "This is a test"; $file = $temp_name; $content = chunk_split(base64_encode(file_get_contents($file))); $uid = md5(uniqid(time())); $header = "From: ".$from."\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".uid."\"\r\n\r\n"; $header .= "This is multi-part message in MIME format. \r\n"; $header .= "--".uid."\r\n"; $header .= "Content-type:txt/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer_Encoding: 7bit\r\n\r\n"; $header .= $message. "\r\n\r\n"; $header .= "--".uid."\r\n"; $header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n"; $header .= $content."\r\n\r\n"; if (mail($to, $subject, "", $header)) { echo "Success"; } else { echo "Failed"; } exit(); } else { echo "File type not allowed"; } } ?> <html> <body> <p>Contact Form</p> <form action="index.php" method="post" enctype="multipart/form-data" name="form1"> <p>First Name: <input type="text" name="firstname"></p> <p>Last Name: <input type="text" name="lastname"></p> <p>E-mail: <input type="text" name="email"></p> <p>Phone Number: <input type="text" name="phonenum"></p> <p>URL: <input type="text" name="url"></p> <p>Project Summary: <input type="textarea" name="prosum" id="prosum"></p> <p>Upload File: <input type="file" name="filename"></p> <p><input type="submit" name="Submit" value="Submit"></p> <?php } ?> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/202083-help/ Share on other sites More sharing options...
jdavidbakr Posted May 17, 2010 Share Posted May 17, 2010 I use htmlMimeMail - it handles all that gritty stuff for you very elegantly. Link to comment https://forums.phpfreaks.com/topic/202083-help/#findComment-1059710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.