j.g. Posted August 23, 2007 Share Posted August 23, 2007 Hello List- This is my first time attempting this; but I'd like to add a file selected by the user to the email that is sent to the recipient... I've got the basics done where it's allowing the input for the name, email, phone, and browsing to select a file; and it's sending an email w/ the name, email, and phone in it, but I don't know how to incorporate the attaching of the email to this email. Here's my code: session_start(); require_once("$DOCUMENT_ROOT/includes/form_functions.php"); require_once("$DOCUMENT_ROOT/includes/form_processor.php"); $to = 'xxx@xxx.net'; $headers = 'From: info@xxx.com' . "\r\n" . 'Reply-To: info@xxx.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Employment Form"; $items = array('name', 'email', 'phone', 'resume file'); $required = array(); if( $_POST["submit"] == "Submit" ) { $required = array( "name" => "text", "email" => "text", "phone" => "text" ); $error_msg = form_processor( $required, $_POST, $num_results = 1 ); if( !$error_msg ) { $message = ''; foreach($items as $i => $item) { $message .= ucfirst($item).": ".$_POST[$item]."\n\r"; } $message .= "Sent: ".date('Y-m-d h:i:s')."\n\r"; if (mail($to, $subject, $message, $headers)) { header ("Location: /thankyouform.php"); exit(); } } } require_once("header.php") Any help or direction that you could give me to get this working is greatly appreciated b/c I just cannot get this working! Thanks, -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/ Share on other sites More sharing options...
lemmin Posted August 23, 2007 Share Posted August 23, 2007 You could try this: http://www.shelldorado.com/articles/mailattachments.html Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/#findComment-332114 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 personally i found phpmailer works really well.. if not then setup the mime etc, see lemmin post Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/#findComment-332115 Share on other sites More sharing options...
j.g. Posted August 23, 2007 Author Share Posted August 23, 2007 Thanks for the replies! I ended up going the phpmailer route; but, am still at the same spot -- sending email w/ name, phone, and email, but file is not attached. Here's my line for it (what's wrong w/ it??): $mail->AddAttachment($_FILES["file_name"]["name"]); And here's my input field for the file: <div align="left">Attach Resume <input TYPE='FILE' NAME='file_name' "SIZE='40'/> </div> Entire php code: session_start(); require_once("$DOCUMENT_ROOT/includes/form_functions.php"); require_once("$DOCUMENT_ROOT/includes/form_processor.php"); //set up the emailer require_once("$LIBRARY_ROOT/class.phpmailer.php"); $mail = new PHPMailer(); $mail->From = 'info@xxx.com'; $mail->FromName = 'info@xxx.com'; $mail->Subject = 'Employment Form Submission'; $items = array('name', 'email', 'phone', 'resume file'); $required = array(); if( $_POST["submit"] == "Submit" ) { $required = array( "name" => "text", "email" => "text", "phone" => "text" ); $error_msg = form_processor( $required, $_POST, $num_results = 1 ); if( !$error_msg ) { $body = ''; foreach($items as $i => $item) { $body .= ucfirst($item).": ".$_POST[$item]."\n\r"; } $body .= "Sent: ".date('Y-m-d h:i:s')."\n\r"; //send the email $mail->Body = $body; $mail->AddAddress('xxx@xxx.net'); $mail->AddAttachment($_FILES["file_name"]["name"]); if ($mail->Send()) { header ("Location: /thankyou.php"); exit(); } else { "There has been an error sending your email to TERM Billing.<br>"; } } } require_once("header.php") Thanks much! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/#findComment-332163 Share on other sites More sharing options...
j.g. Posted August 23, 2007 Author Share Posted August 23, 2007 I've even tried referring to the file directly by using it's 'tmp' value, but still not attaching the file... $mail->AddAttachment($_FILES["file_name"]["tmp"]); Does anyone see what I'm doing wrong? ??? Thanks again! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/#findComment-332181 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 check the upload works by storeing the file in a temp dir, then attach from their, after that unlink the file Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/#findComment-332187 Share on other sites More sharing options...
j.g. Posted August 24, 2007 Author Share Posted August 24, 2007 Thanks for the help! So if anyone else runs into this same issue, this was resolved by tweaking the 'AddAttachment' line: $mail->AddAttachment($_FILES["file_name"]["tmp_name"],$_FILES["file_name"]["name"]); Hope that helps someone else in the future! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66371-solved-adding-attachment-to-email/#findComment-333141 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.