php email form attachments wrong -


so have php file sends info form along attachment specified email addresses. works, when files arrive in email form, attachments don't work , show wrong file type. still learning php. guidance helpful.

here php code.`

<?php  //keep people happy, send email state $firstbdestates = array("ct", "de", "me", "ma", "md", "nh", "nj", "ny", "pa", "ri", "wv", "vt", "va");  $secondbdestates = array("al", "ga", "fl", "ms", "nc", "pr", "sc", "tn"); $thirdbdestates = array("in", "il", "ia", "ky", "mi", "mn", "nd", "ne", "oh", "sd", "wi"); $fourthbdestates = array("az", "ar", "co", "ks", "la", "mo", "nm", "ok", "tx"); $fifthbdestates = array("ak", "ca", "hi", "id", "mt", "nv", "or", "ut", "wa", "wy"); $test = array("test"); //test email don't piss off bde co's // died , error interchangeable names, listed "died" display on  generated page. function died($error) {     echo "we sorry, there error(s) found form submitted. ";     echo "these errors appear below.<br /><br />";     echo $error."<br /><br />";     echo "please use button go  , fix these errors.<br /><br />";     die(); } // backasswords validation.  data listed here in '' trigger  error if not filled out in entirety. if(!isset($_post['mname']) || //a-za-z- !isset($_post['telephone']) || !isset($_post['email']) || !isset($_post['streetline1']) || !isset($_post['towncity']) || //a-za-z- !isset($_post['state']) || !isset($_post['zip']) || !isset($_post['dob']) || !isset($_post['servicebranch']) || !isset($_post['discharge']) || !isset($_post['ratemos']) || !isset($_post['yearsservice']) || !isset($_post['econtactname']) || //a-za-z- !isset($_post['econtactnumber'])  || !isset($_post['ndaagree']) || !isset($_post['username']) || !isset($_post['password']) || !isset($_post['tosagree']) || !isset($_post['wolagree'])) { died('<span style="color:#ff0000">one or more fields not filled out.</span>');        } //email validation $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/';  if(!preg_match($email_exp,$email_from)) {     $error_message .= 'the email address entered not appear valid.<br />';  } // simple sanitization unwanted characters a-za-z- $string_exp = "/^[a-za-z .'-]+$/";   if(!preg_match($string_exp,$mname)) {     $error_message .= 'the name entered not appear valid.<br />';    } $string_exp = "/^[a-za-z .'-]+$/";   if(!preg_match($string_exp,$towncity)) {     $error_message .= 'the town or city entered not appear valid.<br />';    } $string_exp = "/^[a-za-z .'-]+$/";   if(!preg_match($string_exp,$econtactname)) {     $error_message .= 'the emergency contact name entered not appear valid.<br />';    }  // callout form data...what bitch! $mname = $_post['mname']; // required $telephone = $_post['telephone']; // required $email = $_post['email']; // required $streetline1 = $_post['streetline1']; // required $streetline2 = $_post['streetline2']; // required $towncity = $_post['towncity']; // required $state = $_post['state']; // required $zip = $_post['zip']; // required $dob = $_post['dob']; // required $servicebranch = $_post['servicebranch']; // required $discharge = $_post['discharge']; // required $ratemos = $_post['ratemos']; // required $yearsservice = $_post['yearsservice']; // required $econtactname = $_post['econtactname']; // required $econtactnumber = $_post['econtactnumber']; // required $ndaagree = $_post['ndaagree']; // required $username = $_post['username']; // required $password = $_post['password']; // required $tosagree = $_post['tosagree']; // required $wolagree = $_post['wolagree']; // required // // //callout error message $error_message = ""; //turn on error reporting can see screw error_reporting(e_all); ini_set('display_errors', 1); // file upload server---then pull server if(isset($_files) && (bool) $_files) {     $allowedextensions = array("pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt"); // allowed file types     $files = array();     foreach($_files $name=>$file) {         $file_name = $file['name'];          $temp_name = $file['tmp_name'];         $file_type = $file['type'];         $path_parts = pathinfo($file_name);         $ext = $path_parts['extension'];         if(!in_array($ext,$allowedextensions)) {             die("either did not select file or incorrect file type.  please try again.");         }         array_push($files,$file);     }     //if no errors, proceed     // email fields: to, from, subject, , on , on.  format pretty people smile     $to = myfunction();     $from = "webmaster@warriorpointe.org";      $subject ="$mname has requested join";     $message = "<span style='color:#ff0000';>*** email contains sensitive member information ***</span><br />                 greetings bde co, <br />                 today, $mname has requested join warrior pointe , within brigade limits. receiving message because assigned. please ensure set members forum account.  if unable to, please notify patrick or robert , can build you.<br />                 <span style='color:#ff0000'>*** email contains sensitive member information ***</span><br /><br /><br />                 ";     // geek translator - crap in english don't yelled @     $message .="members name: ".clean_string($mname)."\n <br /> contact number: ".clean_string($telephone)."\n <br /> email: ".clean_string($email)."\n <br /> street address: ".clean_string($streetline1)."\n <br /> street address 2: ".clean_string($streetline2)."\n <br /> town or city: ".clean_string($towncity)."\n <br /> state: ".clean_string($state)."\n <br /> zip code: ".clean_string($zip)."\n <br /> date of birth: ".clean_string($dob)."\n <br /> branch of service: ".clean_string($servicebranch)."\n <br /> discharge status: ".clean_string($discharge)."\n <br /> rate or mos: ".clean_string($ratemos)."\n <br /> years of service: ".clean_string($yearsservice)."\n <br /> emergency contact name: ".clean_string($econtactname)."\n <br /> emergency contact number: ".clean_string($econtactnumber)."\n <br /> nda agreement: ".clean_string($ndaagree)."\n <br /> waiver of liability: ".clean_string($wolagree)."\n <br /> forum tos agree: ".clean_string($tosagree)."\n <br /> forum user name: ".clean_string($username)."\n <br /> forum password: ".clean_string($password)."\n <br />";      $message .="<span style='color:#ff0000'>*** end of message ***</span>";     // tell them message     $headers = "from: $from";     // boundary      $semi_rand = md5(time());      $mime_boundary = "==multipart_boundary_x{$semi_rand}x";       // headers attachment      $headers .= "\nmime-version: 1.0\n" . "content-type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";       // multipart boundary      $message = "this multi-part message in mime format.\n\n" . "--{$mime_boundary}\n" . "content-type: text/html; charset=\"iso-8859-1\"\n" . "content-transfer-encoding: 8bit\n\n" . $message . "\n\n";      $message .= "--{$mime_boundary}\n";      // preparing attachments     for($x=0;$x<count($files);$x++){         $file = fopen($files[$x]['tmp_name'],"rb");         $data = fread($file,filesize($files[$x]['tmp_name']));         fclose($file);         $data = chunk_split(base64_encode($data));         $name = $files[$x]['name'];         $message .= "content-type: {$filetype};\n" . " name=\"$name\"\n" .          "content-disposition: attachment;\n" . " filename=\"$name\"\n" .          "content-transfer-encoding: base64\n\n" . $data . "\n\n";         $message .= "--{$mime_boundary}\n";     }     // send form jeeves      $ok = mail($to, $subject, $message, $headers);      if ($ok) {           echo "<img src='images/png/apple-touch-icon-128.png'><br />thank registering warrior pointe.  registration form has been forwarded correct brigade staff processing.  typical processing time no more 72 hours.  if have not heard form brigade staff within 72 hours, please email webmaster@warriorpointe.org.<br/><br/>";                 } else {                     echo '<div style="color: red">' . $errors . '<br/></div>';                 }     } // how dang sender knows mail too. function myfunction() {     if (in_array($_post['state'], $globals["firstbdestates"])) {         return "1stbdecommander@warriorpointe.org, hr@warriorpointe.org, webmaster@warriorpointe.org, archive@warriorpointe.org";     }      else if (in_array($_post['state'], $globals["secondbdestates"])) {         return "2ndbdecommander@warriorpointe.org, hr@warriorpointe.org, webmaster@warriorpointe.org, archive@warriorpointe.org";     }      else if (in_array($_post['state'], $globals["thirdbdestates"])) {         return "3rdbdecommander@warriorpointe.org, hr@warriorpointe.org, webmaster@warriorpointe.org, archive@warriorpointe.org";      }      else if (in_array($_post['state'], $globals["fourthbdestates"])) {      return "4thbdecommander@warriorpointe.org, hr@warriorpointe.org, webmaster@warriorpointe.org, archive@warriorpointe.org";     }      else if (in_array($_post['state'], $globals["fifthbdestates"])) {         return "5thbdecommander@warriorpointe.org, hr@warriorpointe.org, webmaster@warriorpointe.org, archive@warriorpointe.org ";      }     else if (in_array($_post['state'], $globals["test"])) {         return "webmaster@warriorpointe.org";     }      else {         return "president@warriorpointe.org, webmaster@warriorpointe.org,   archive@warriorpointe.org";         }  } function clean_string($string) {     $bad = array("content-type","bcc:","to:","cc:","href");     return str_replace($bad,"",$string);} ?>` 

you can use php mailer class send attachment

here class https://github.com/phpmailer/phpmailer/blob/master/class.phpmailer.php

and here code of how send attachment

$mail = new phpmailer(); // defaults using php "mail()"         $mail->setfrom('abc@abc.com', 'abc@abc.com');         $address = 'xyz@xyz.com';         $mail->subject = 'test';         $mail->altbody = "to view message, please use html compatible email viewer!"; // optional          $mail->msghtml('this test message');         $mail->ishtml(true);          $mail->addattachment("images/logo1.png"); // attachment         $mail->addattachment("images/engr mudasir.jpg"); // attachment          if(!$mail->send()) {             echo $output = $mail->errorinfo;         } else {             echo $output = 'thank you';         } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -