Stickybomb Posted June 18, 2007 Share Posted June 18, 2007 ok i am working on a form and need to provide the ability to attach an image in the mail that will be sent. for some reason though it is not sending the mail <?php //initalized form variables $firstname=''; $lastname=''; $mailing=''; $shipping=''; $phone=''; $fax=''; $email=''; $contactname=''; $company=''; $comments=''; $quantity=''; //header check array $check = array("%0A", "%0D", "bcc:", "cc:", "mime-type:", "content-type:", "from:", "to:", "Bcc:", "Cc:", "Mime-Type:", "Content-Type:", "From:", "To:", "\\r", "\\n", "\\" ); $error=0; if(isset($_POST['submitted']) == "yes"){ if(!empty($_POST['firstname'])){$firstname = $_POST['firstname'];}else{$firstname='';} if(!empty($_POST['lastname'])){$lastname = $_POST['lastname'];}else{$lastname='';} if(!empty($_POST['mailing'])){$$mailing = $_POST['mailing'];}else{$mailing='';} if(!empty($_POST['shipping'])){$shipping = $_POST['shipping'];}else{$shipping='';} if(!empty($_POST['phone'])){$phone = $_POST['phone'];}else{$phone='';} if(!empty($_POST['fax'])){$fax = $_POST['fax'];}else{$fax='';} if(!empty($_POST['contactname'])){$contactname = $_POST['contactname'];}else{$contactname='';} if(!empty($_POST['company'])){$company = $_POST['company'];}else{$company='';} if(!empty($_POST['quantity'])){$quantity = $_POST['quantity'];}else{$quantity='';} if(!empty($_POST['comments'])){$comments = $_POST['comments'];}else{$comments='';} //check for injections $firstname = str_replace($check, "", $firstname); $lastname = str_replace($check, "", $lastname); $mailing = str_replace($check, "", $mailing); $shipping = str_replace($check, "", $shipping); $phone = str_replace($check, "", $phone); $fax = str_replace($check, "", $fax); $contactname = str_replace($check, "", $contactname); $company = str_replace($check, "", $company); $quantity = str_replace($check, "", $quantity); $comments = str_replace($check, "", $comments); if (eregi('<a href',$firstname)){$error=1;} if (eregi('<a href',$lastname)){$error=1;} if (eregi('<a href',$mailing)){$error=1;} if (eregi('<a href',$shipping)){$error=1;} if (eregi('<a href',$phone)){$error=1;} if (eregi('<a href',$fax)){$error=1;} if (eregi('<a href',$contactname)){$error=1;} if (eregi('<a href',$company)){$error=1;} if (eregi('<a href',$quantity)){$error=1;} if (eregi('<a href',$comments)){$error=1;} if($error!=1){ //create message $to='mike@whitemyer.com'; $subject='Quote Request'; $message= "The following quote request was submitted:\n First Name - ". $firstname . "\n Last Name - ". $lastname . "\n Company - ". $company . "\n Mailing Address - ". $mailing . "\n Shipping Address - ". $shipping . "\n Phone - ". $phone . "\n Fax - ". $fax . "\n E-Mail - ". $email . "\n Contact Name - ". $contactname . "\n Quoe Quantity - ". $quantity . "\n Comments - " . $comments."\n"; $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = 'From: '.$company ."\r\n"; $headers .= 'Bcc: '; $headers .= 'Cc: '; 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=\"utf-8\"\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"; } //send results $ok=@mail($to, $subject, $message, $headers); if ($ok) { echo "<p>Thank you! Your request has been successfully submited.</p>"; } else { echo "<p>Request could not be sent. Sorry! (01)</p>"; } }else{ echo "<p>Request could not be sent. Sorry! 02</p>"; } //Else display form i am getting the error msg i created with the (01) appended to it which implies that the ok variable is not recieving a value it is the exact same method i am using on another form i created which works fine, the only difference is the fields them self the other one has less fields then this one. Quote Link to comment https://forums.phpfreaks.com/topic/56065-solved-file-attahment-in-mail-help/ Share on other sites More sharing options...
nick_whitmarsh Posted June 18, 2007 Share Posted June 18, 2007 Not really sure with things, but checking through your code, at the very bottom you have (1) with your first error but not brackets around the two! Nick Quote Link to comment https://forums.phpfreaks.com/topic/56065-solved-file-attahment-in-mail-help/#findComment-276882 Share on other sites More sharing options...
Stickybomb Posted June 18, 2007 Author Share Posted June 18, 2007 that is just an echoed piece of text called if error==1 its not code, and has no effect on the code itself Quote Link to comment https://forums.phpfreaks.com/topic/56065-solved-file-attahment-in-mail-help/#findComment-276936 Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 Well you might want to stop suppressing the errors on your mail function. Try removing the @ symbol from this line: $ok=@mail($to, $subject, $message, $headers); And see if php gives you a usefull error message. Quote Link to comment https://forums.phpfreaks.com/topic/56065-solved-file-attahment-in-mail-help/#findComment-276947 Share on other sites More sharing options...
Stickybomb Posted June 18, 2007 Author Share Posted June 18, 2007 hmm thks for the tip i didn't even see that there ???, it seems it failed because of an empty CC: in the headers Quote Link to comment https://forums.phpfreaks.com/topic/56065-solved-file-attahment-in-mail-help/#findComment-276956 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.