Jump to content

wolfsta

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

About wolfsta

  • Birthday 05/12/1982

Profile Information

  • Gender
    Male

wolfsta's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok so ended up going back to my code.. As it seemed to be closer.. with the help of a friend realized the MIME encoding stuff wasn't quite right. Here is the fixed working code just have to add multiple file support now: $attachment = $path_of_uploaded_file; $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers = "MIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message .= "Form details below:"."<br>"."<br>"; $email_message .= "First Name:"."\t".clean_string($first_name). "<br>"; $email_message .= "Last Name:"."\t".clean_string($last_name)."<br>"; $email_message .= "Age:"."\t".clean_string($age)."<br>"; $email_message .= "Height:"."\t".clean_string($height_feet).'ft ' . clean_string($height_inches).'in'."<br>"; $email_message .= "City:"."\t".clean_string($city)."<br>"; $email_message .= "State:"."\t".clean_string($state)."<br>"; $email_message .= "Email:"."\t".clean_string($email_from)."<br>"; $email_message .= "Telephone:"."\t".clean_string($telephone)."<br>"; $email_message .= "Comments:"."\t".clean_string($comments)."<br>"."<br>"."\n"; $data = chunk_split(base64_encode($data)); $email_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"; // create email headers $headers .= "\n" . 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers);
  2. my html.. the form bit with photos. </div> <label class="message"> <span class="text-form">Comments:</span> <textarea name="comments"></textarea> </label> <label> <span class="text-form2">Attach a photo:</span> <input type="file" name="uploadFiles" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input type="file" name="uploadFiles" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input type="file" name="uploadFiles" class="fl" > </label> <div class="but"><a class="link1 link-color2" data-type="submit" onClick="document.getElementById('form2').submit()">Submit</a></div> </fieldset> </form>
  3. this is all i did: <?php $to = 'wolfsta@domain.com'; if(isset($_FILES['uploadFiles']['name'])) { foreach ($_FILES['uploadFiles']['name'] as $i => $name) { if ($_FILES['uploadFiles']['error'][$i] == 4) { continue; } if ($_FILES['uploadFiles']['error'][$i] == 0) { if ($_FILES['uploadFiles']['size'][$i] > 99439443) { $messages[] = "$name exceeded file limit."; continue; } if(move_uploaded_file($_FILES['uploadFiles']['tmp_name'][$i], "../uploads/$name")) { $uploaded++; $files[] = "../uploads/$name"; } else { echo "Could not upload $name to be attached!<br />"; } } } //$files = $_FILES['uploadFiles']['tmp_name']; } echo "$uploaded receipt"; if($uploaded != 1) { echo "s"; } echo " uploaded."; foreach ($messages as $error) { echo $error; } // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $eol = PHP_EOL; $headers = "From: ".$to.$eol; $headers .= "Reply-To: ".$to.$eol; $subject = "Expense Report - Period Ending $reportDate"; $headers .= $eol."MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol; // no more headers after this, we start the body! // //$body = "--".$mime_boundary.$eol; //$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $body .= "This is a multi-part message in MIME format.".$eol; // message $body .= "--".$mime_boundary.$eol; $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $body .= $message.$eol.$eol; if($uploaded > 0) { // if there are attachments add this line to the message, otherwise with no attachments this line will add an unwanted attachment //$body .= "--{$mime_boundary}\n"; } if(isset($_FILES['uploadFiles']['name'])) { // preparing attachments for($x=0;$x<count($files);$x++){ $file = fopen($files[$x],"rb"); $data = fread($file,filesize($files[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $name = $_FILES['uploadFiles']['name'][$x]; /*$body .= "–{$mime_boundary}\n"; $body .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; //$body .="--{$mime_boundary}--\n"; if ($x==count($files)-1) { //$message .="--{$mime_boundary}-\n"; } else{ //$message .="--{$mime_boundary}\n"; }*/ // attachment $body .= "--".$mime_boundary.$eol; $body .= "Content-Type: application/octet-stream; name=\"".$name."\"".$eol; $body .= "Content-Transfer-Encoding: base64".$eol; $body .= "Content-Disposition: attachment".$eol.$eol; $body .= $data.$eol.$eol; } $body .= "--".$mime_boundary."--"; } // send $ok = @mail($to, $subject, $body, $headers); if ($ok) { echo "<p>Email sent to $to!</p>"; } else { echo "<p>Email could not be sent!</p>"; } ?>
  4. Mike I tried to use your script but I cant get it to work at all. I deleted all my code and just used yours and added my email address to the variable $to and it doesn't work. Changed the name= in my html form to uploadedFiles... I get the email but no attachment at all Any suggestions?
  5. Awesome thanks Mike, I'll see if I can tie it into mine. Wolfsta
  6. Any one know how to do this? or have a simpler way of attaching file? I tried using getimagesize() to return the MIME type but it gave me txt html for a jpg??
  7. Entire php if you need to look at it. I know its probably quite messy or better ways to do it but I'm a novice, ill tidy up as I go and learn: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "asdfasd@adskfjh.com"; $email_subject = "asdf asdfasdf Application Form"; function died($error) { // your error code can go here ?> <title>asdfas asdf</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfadsf" longdesc="http://www.adsfasdf.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>Please fix the following errors:</p> <hr /> <br /> <?php echo $error; ?> <hr /> <br /> <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asdfasdf 2012</h6> </body> </html> <?php die(); } // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches']; //Get the uploaded file information $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); //get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs //Settings $max_allowed_file_size = 500000; // size in KB $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png"); //Validations if($size_of_uploaded_file > $max_allowed_file_size ) { $errors .= "\n Size of file should be less than $max_allowed_file_size"; } //------ Validate the file extension ----- $allowed_ext = false; for($i=0; $i<sizeof($allowed_extensions); $i++) { if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) { $allowed_ext = true; } } if(!$allowed_ext) { $errors .= "\n The uploaded file is not supported file type. ". " Only the following file types are supported: ".implode(',',$allowed_extensions); } //copy the temp. uploaded file to uploads folder $upload_folder = "../uploads/"; $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["uploaded_file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)) { $errors .= '\n error while copying the uploaded file'; } } $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'First Name: This is not a valid name.<br /><br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'Last Name: This is not a valid last name.<br /><br />'; } $age_exp = "/^(1[89]|[2-9][0-9])$/"; if(!preg_match($age_exp,$age)) { $error_message .= 'Age: You need to be at least 18+ to apply.<br /><br />'; } $phone_exp = "/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/"; if(!preg_match($phone_exp,$telephone)) { $error_message .= 'Phone: eg 646 555 1234 or 646-555-1234 or (646) 555 1234<br /><br />'; } $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'Email: Your address is not invalid eg yourname@emaildomain.com<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'Comments: Please leave a breif message explaining your interest and if you have any previous experience etc.<br /><br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below:\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name:"."\t".clean_string($first_name)."\n"; $email_message .= "Last Name:"."\t".clean_string($last_name)."\n"; $email_message .= "Age:"."\t".clean_string($age)."\n"; $email_message .= "Height:"."\t".clean_string($height_feet).'ft ' . clean_string($height_inches).'in'."\n"; $email_message .= "City:"."\t".clean_string($city)."\n"; $email_message .= "State:"."\t".clean_string($state)."\n"; $email_message .= "Email:"."\t".clean_string($email_from)."\n"; $email_message .= "Telephone:"."\t".clean_string($telephone)."\n"; $email_message .= "Comments:"."\t".clean_string($comments)."\n"; $attachment = $path_of_uploaded_file; $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $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}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $data = chunk_split(base64_encode($data)); $email_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"; // create email headers $headers .= 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <title>adsfadsf adsfadsf</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.asdfasdf.com" /><br /> </p> <p>Thank your for applying to asdfadsf asdfadsf. We will be in touch with you very soon.</p> <p>You will be redirected back to the site in 10 seconds...</p> <h6> </h6> <h6>© asdfasdf 2012</h6> </body> </html> <?php } ?>
  8. Hi all I have a script that I have patched together and got to work in pieces. I'm up to the last part. I have the form working and emailing. It also will upload an image by itself and put it in a folder. Now i just need to tie those together and have the image put in the email as an attachment then deleted from server. I have it at a stage where it sends me the users details.. and it tries to send the photo but it comes through as junk txt. I think its the MIME encoding stuff that I have wrong.. not sure? Here's what I have so far. $attachment = $path_of_uploaded_file; $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $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}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $data = chunk_split(base64_encode($data)); $email_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"; // create email headers $headers .= 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); Thanks Wolfsta
  9. Solved that part.. was the folder permissions changed to ../uploads/ and chmod to 777 and it now uploads the file. Can anyone tell me how I can now get it to send it with the email as an attachment then remove the file from server. Thanks Wolfsta
  10. So I found this code and it seems to go through the upload process in the browser.. but it doesn't copy it to my upload folder.. //Get the uploaded file information $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); //get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs //Settings $max_allowed_file_size = 500000; // size in KB $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png"); //Validations if($size_of_uploaded_file > $max_allowed_file_size ) { $errors .= "\n Size of file should be less than $max_allowed_file_size"; } //------ Validate the file extension ----- $allowed_ext = false; for($i=0; $i<sizeof($allowed_extensions); $i++) { if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) { $allowed_ext = true; } } if(!$allowed_ext) { $errors .= "\n The uploaded file is not supported file type. ". " Only the following file types are supported: ".implode(',',$allowed_extensions); } //copy the temp. uploaded file to uploads folder $upload_folder = "./upload/"; $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["uploaded_file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)) { $errors .= '\n error while copying the uploaded file'; } } If it makes a difference I inserted that into the previous posts php just after this section: $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches'];
  11. Hi Have got my form working for all standard bits. Just need to add the functionality for people to upload photos. I copied and modified the form from a site and there is a section that I think is redundant it still works when I comment it out can you clarify for me: // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ Below is the full code for the form: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "asdfasdf@asdfasdf.com"; $email_subject = "adsfasdf asdfasdf Application Form"; function died($error) { // your error code can go here ?> <title>asdfas asdfasd</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.adsfasdf.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>Please fix the following errors:</p> <hr /> <br /> <?php echo $error; ?> <hr /> <br /> <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asdfasdf 2012</h6> </body> </html> <?php die(); } // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches']; $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'First Name: This is not a valid name.<br /><br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'Last Name: This is not a valid last name.<br /><br />'; } $age_exp = "/^(1[89]|[2-9][0-9])$/"; if(!preg_match($age_exp,$age)) { $error_message .= 'Age: You need to be at least 18+ to apply.<br /><br />'; } $phone_exp = "/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/"; if(!preg_match($phone_exp,$telephone)) { $error_message .= 'Phone: eg 646 555 1234 or 646-555-1234 or (646) 555 1234<br /><br />'; } $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'Email: Your address is not invalid eg yourname@emaildomain.com<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'Comments: Please leave a breif message explaining your interest and if you have any previous experience etc.<br /><br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below:\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name:"."\t".clean_string($first_name)."\n"; $email_message .= "Last Name:"."\t".clean_string($last_name)."\n"; $email_message .= "Age:"."\t".clean_string($age)."\n"; $email_message .= "Height:"."\t".clean_string($height_feet).'ft ' . clean_string($height_inches).'in'."\n"; $email_message .= "City:"."\t".clean_string($city)."\n"; $email_message .= "State:"."\t".clean_string($state)."\n"; $email_message .= "Email:"."\t".clean_string($email_from)."\n"; $email_message .= "Telephone:"."\t".clean_string($telephone)."\n"; $email_message .= "Comments:"."\t".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <title>adsfas asdfasdf</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.asdfasdf.com" /><br /> </p> <p>Thank your for applying to asdf adsf. We will be in touch with you very soon.</p> <p>You will be redirected back to the site in 10 seconds...</p> <h6> </h6> <h6>© adsfdasf 2012</h6> </body> </html> <?php } ?> Here is the html form: <form id="form2" action="./php/joinus.php" method="post" enctype="multipart/form-data"> <fieldset> <div class="wrapper"> <div class="fleft col"> <label class="first_name"> <span class="text-form">Name:</span> <input name="first_name" type="text" value=""> </label> <label class="age"> <span class="text-form">Age:</span> <input name="age" type="tel" value=""> </label> <label class="city"> <span class="text-form">City:</span> <input name="city" type="text" value=""> </label> <label class="telephone"> <span class="text-form">Phone:</span> <input name="telephone" type="tel" value=""> </label> </div> <div class="fleft col2"> <label class="last_name"> <span class="text-form">Last Name:</span> <input name="last_name" type="text" value=""> </label> <span id="validate_height"> <label><span class="text-form">Height:</span> <select style="width:109px;" name="height_feet"> <option value="" selected="selected">Feet</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> <select style="width:109px;" name="height_inches"> <option value="" selected="selected">Inches</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> </select> </label> </span> <label class="state"> <span class="text-form">State:</span> <select name="state"> <option value="" selected="selected">Select a State</option> <option value="Alabama">Alabama</option> <option value="Alaska">Alaska</option> <option value="Arizona">Arizona</option> <option value="Arkansas">Arkansas</option> <option value="California">California</option> <option value="Colorado">Colorado</option> <option value="Connecticut">Connecticut</option> <option value="Delaware">Delaware</option> <option value="District Of Columbia">District Of Columbia</option> <option value="Florida">Florida</option> <option value="Georgia">Georgia</option> <option value="Hawaii">Hawaii</option> <option value="Idaho">Idaho</option> <option value="Illinois">Illinois</option> <option value="Indiana">Indiana</option> <option value="Iowa">Iowa</option> <option value="Kansas">Kansas</option> <option value="Kentucky">Kentucky</option> <option value="Louisiana">Louisiana</option> <option value="Maine">Maine</option> <option value="Maryland">Maryland</option> <option value="Massachusetts">Massachusetts</option> <option value="Michigan">Michigan</option> <option value="Minnesota">Minnesota</option> <option value="Mississippi">Mississippi</option> <option value="Missouri">Missouri</option> <option value="Montana">Montana</option> <option value="Nebraska">Nebraska</option> <option value="Nevada">Nevada</option> <option value="New Hampshire">New Hampshire</option> <option value="New Jersey">New Jersey</option> <option value="New Mexico">New Mexico</option> <option value="New York">New York</option> <option value="North Carolina">North Carolina</option> <option value="North Dakota">North Dakota</option> <option value="Ohio">Ohio</option> <option value="Oklahoma">Oklahoma</option> <option value="Oregon">Oregon</option> <option value="Pennsylvania">Pennsylvania</option> <option value="Rhode Island">Rhode Island</option> <option value="South Carolina">South Carolina</option> <option value="South Dakota">South Dakota</option> <option value="Tennessee">Tennessee</option> <option value="Texas">Texas</option> <option value="Utah">Utah</option> <option value="Vermont">Vermont</option> <option value="Virginia">Virginia</option> <option value="Washington">Washington</option> <option value="West Virginia">West Virginia</option> <option value="Wisconsin">Wisconsin</option> <option value="Wyoming">Wyoming</option> </select> </label> <label class="email"> <span class="text-form">E-mail:</span> <input name="email" type="text" value=""> </label> </div> </div> <label class="message"> <span class="text-form">Comments:</span> <textarea name="comments"></textarea> </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <div class="but"><a class="link1 link-color2" data-type="submit" onClick="document.getElementById('form2').submit()">Submit</a></div> </fieldset> </form> From what I've been reading you need to tell the php to put it to a temporary file from the submit.. then move it to the file name and then somehow include that file name in the php email back. So maybe a url and its private or htaccess? or does it get included as attachment in the mail? Im not sure if i should be using 'id' or 'name' in the html form etc and how to tie it together. Any help or guides much appreciated. Thanks Wolfsta
  12. Thanks after what you said it made me go back and look. I just needed to add this in the middle of my html to get it to display. <?php echo $error."<br /><br />"; ?> But I will go back and tidy up into an html file like you suggested after. Thanks guys! Wolfsta
  13. Sorry let me explain a little more.. this is the original code that i got from a website. I started messing with it. <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "you@yourdomain.com"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $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 you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> Instead of just displaying a error in plain text. I want it to display nicely on a html page with logo and everything then the errors and also redirect back to the form after say 10seconds. I took the error section and ended the php tag.. inserted html.. and then started the php at the end again as below: function died($error) { // your error code can go here ?> <title>asdf adsf</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onload="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfa" longdesc="http://www.adsfadsf.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>These errors appear below.</p> <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asdf 2012</h6> </body> </html> <?php die(); } But i realised that the errors were generated from the php so can you provide either and easier way to display a full page and logo when it does the errors, or b inserted the errors via php into the html section. Hope I'm explaining this clearly. Thanks Wolfsta
  14. Hi all New here. I have a basic email form that takes name phone email etc, also has 3 file upload boxes for photos. I have taken most of the code from free examples off the net and patched it together. It had an error message if something went wrong. I wanted to put an html page instead of just the txt. So read that I could end tag the php then do html then begin tag the php again. Problem is some of the error message was from a different part of the php code. How can i get this displayed on the html. <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "email@email.com"; $email_subject = "JoinUs Model Form"; function died($error) { // your error code can go here ?> <title>title</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onload="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="sdadfsd" longdesc="http://www.dgfsfdg.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>These errors appear below.</p> ####### this is where i want the below errors to appear in same format as html ######### <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asafdsodf 2012</h6> </body> </html> <?php die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['form2']['photo1']); $target_path = $target_path . basename( $_FILES['form2']['photo2']); $target_path = $target_path . basename( $_FILES['form2']['photo3']); $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches']; $photo1 = $_FILES['form2']['photo1']; $photo2 = $_FILES['form2']['photo2']; $photo3 = $_FILES['form2']['photo3']; $error_message = ""; $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 you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Age: ".clean_string($age)."\n"; $email_message .= "Height: ".clean_string($height_feet) .clean_string($height_inches)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "State: ".clean_string($state)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $email_message .= "".clean_string($comments)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>asdf </title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF"> <p><img src="./images/logo.png" width="326" height="144" alt="asdfahjdsfka" longdesc="http://www.kasdfhdskaha.com" /><br /> </p> <p>Thank your for applying to adskfha asdfasd. We will be in touch with you very soon.</p> <p>You will be redirected back to the site in 3 seconds...</p> <h6> </h6> <h6>© 2012</h6> </body> </html> <?php } ?> Thanks Wolfsta
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.