Jump to content
Larry Ullman's Book Forums

BobC1970

Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About BobC1970

  • Rank
    Newbie
  1. Sorry, yes of course: http://www.naturetravels.co.uk/book-online.php As mentioned, this only happens with a small number of submissions, but particular customers (I assume using the same email address each time) will never be able to send a form successfully. From searching around, it seems problems with the "From" header can cause delivery difficulties. I've come across the following suggestions: - The "From" header shouldn't be the value of "email" from the form (that is the address of the person sending the form, as per the standard script) but must be set to be an address from my domain. Is that right? If so, that makes the inbox hard to organise as all forms will have the same sender. If this is in fact the solution, can the value of "email" be appended to the "Subject" parameter so that subjects read "Online booking form from example@example.com" or would that cause problems? - That using ini_set can help to avoid incorrect FROM header: $email_from = $scrubbed['email']; ini_set("sendmail_from", $email_from); $headers = "From: $email_from"; then mail('OUR EMAIL ADDRESS', 'Online Booking Form', $body, $headers) I've also just noticed that my wordwrap has been set to 90 characters rather than the recommended 70 (I've just reread that part of the book - didn't realise this was important). Could resetting to 70 help? $body = wordwrap($body, 90);
  2. We have been using the following script (based on the book script) to deliver a booking form very successfully for some time. However, just recently occasionally a customer submits a form that is not delivered, despite them coming to the "thank you" confirmation. We do not receive the form, does not go to spam, etc. Despite repeated attempts, these customers cannot send the form successfully, while we receive many other forms without problems. Is there anything in the code that would allow the customer to get through to the "confirmation" part while the "send" is not executed successfully? Or could the only explanation be a problem in the delivery chain rather than our implementation of the form? Any advice would be appreciated, thank you. Our script is: <?php # Script 12.1 - email.php #2 // Check for form submission: if (isset($_POST['submitted'])) { /* The function takes one argument: a string. * The function returns a clean version of the string. * The clean version may be either an empty string or * just the removal of all newline characters. */ function spam_scrubber($value) { // List of very bad values: $very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:', '#'); // If any of the very bad strings are in // the submitted value, return an empty string: foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ''; } // Replace any newline characters or link code characters with spaces: $value = str_replace(array( "\r", "\n", "%0a", "%0d", "http://", "www.", "<a", "</a>"), ' ', $value); // Return the value: return trim($value); } // End of spam_scrubber() function. // Clean the form data: $scrubbed = array_map('spam_scrubber', $_POST); // Minimal form validation: if (!empty($scrubbed['accept_conditions'])) { // Create the body: $body = 'Sent At ' . date("H:i:s") . ' on ' . date("d/m/Y") . "\n\nSent By {$scrubbed['contact_name']} {$scrubbed['email']}\n\n-----------------\n\nEXPERIENCE 1\n\nExperience Name: {$scrubbed['experience_name']}\n\nStart Date: {$scrubbed['experience_start']}\n\nEnd Date: {$scrubbed['experience_end']}\n\n\n\nEXPERIENCE 2\n\nExperience Name 2: {$scrubbed['experience_name_2']}\n\nStart Date 2: {$scrubbed['experience_start_2']}\n\nEnd Date 2: {$scrubbed['experience_end_2']}\n\n\n\nPERSONAL DETAILS\n\nPERSON ONE\n\nName: {$scrubbed['one_first_name']} {$scrubbed['one_surname']}\n\nNationality: {$scrubbed['one_nationality']}\n\nDOB: {$scrubbed['one_dob']}\n\nGender: {$scrubbed['one_gender']}\n\nHealth-Diet: {$scrubbed['one_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['one_ins_co']}, {$scrubbed['one_pol_no']}, {$scrubbed['one_exp_date']}\n\n\nPERSON TWO\n\nName: {$scrubbed['two_first_name']} {$scrubbed['two_surname']}\n\nNationality: {$scrubbed['two_nationality']}\n\nDOB: {$scrubbed['two_dob']}\n\nGender: {$scrubbed['two_gender']}\n\nHealth-Diet: {$scrubbed['two_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['two_ins_co']}, {$scrubbed['two_pol_no']}, {$scrubbed['two_exp_date']}\n\n\nPERSON THREE\n\nName: {$scrubbed['three_first_name']} {$scrubbed['three_surname']}\n\nNationality: {$scrubbed['three_nationality']}\n\nDOB: {$scrubbed['three_dob']}\n\nGender: {$scrubbed['three_gender']}\n\nHealth-Diet: {$scrubbed['three_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['three_ins_co']}, {$scrubbed['three_pol_no']}, {$scrubbed['three_exp_date']}\n\n\nPERSON FOUR\n\nName: {$scrubbed['four_first_name']} {$scrubbed['four_surname']}\n\nNationality: {$scrubbed['four_nationality']}\n\nDOB: {$scrubbed['four_dob']}\n\nGender: {$scrubbed['four_gender']}\n\nHealth-Diet: {$scrubbed['four_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['four_ins_co']}, {$scrubbed['four_pol_no']}, {$scrubbed['four_exp_date']}\n\n\nPERSON FIVE\n\nName: {$scrubbed['five_first_name']} {$scrubbed['five_surname']}\n\nNationality: {$scrubbed['five_nationality']}\n\nDOB: {$scrubbed['five_dob']}\n\nGender: {$scrubbed['five_gender']}\n\nHealth-Diet: {$scrubbed['five_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['five_ins_co']}, {$scrubbed['five_pol_no']}, {$scrubbed['five_exp_date']}\n\n\nPERSON SIX\n\nName: {$scrubbed['six_first_name']} {$scrubbed['six_surname']}\n\nNationality: {$scrubbed['six_nationality']}\n\nDOB: {$scrubbed['six_dob']}\n\nGender: {$scrubbed['six_gender']}\n\nHealth-Diet: {$scrubbed['six_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['six_ins_co']}, {$scrubbed['six_pol_no']}, {$scrubbed['six_exp_date']}\n\n\n\nOPTIONAL EXTRAS\n\n{$scrubbed['optional_extras']}\n\n\n\nCLIMATE CARE OR CHARITY DONATION\n\nPerson 1: {$scrubbed['one_charity']}\n\nPerson 2: {$scrubbed['two_charity']}\n\nPerson 3: {$scrubbed['three_charity']}\n\nPerson 4: {$scrubbed['four_charity']}\n\nPerson 5: {$scrubbed['five_charity']}\n\nPerson 6: {$scrubbed['six_charity']}\n\n\n\nCONTACT DETAILS\n\nContact Name: {$scrubbed['contact_name']}\n\nContact Address: {$scrubbed['contact_address']}\n\nContact Town: {$scrubbed['contact_town']}\n\nContact Postcode: {$scrubbed['contact_postcode']}\n\nContact Telephone: {$scrubbed['contact_tel']}\n\nContact Mobile: {$scrubbed['contact_mobile']}\n\nContact Email: {$scrubbed['email']}\n\nNewsletter: {$scrubbed['newsletter']}\n\n\n\nEMERGENCY CONTACT\n\nEmergency Name: {$scrubbed['emergency_name']}\n\nEmergency Telephone: {$scrubbed['emergency_tel']}\n\nEmergency Mobile: {$scrubbed['emergency_mobile']}\n\nPAYMENT INFORMATION\n\nDeposit Total: {$scrubbed['deposit_total']}\n\nDonation Total: {$scrubbed['climate_care_total']}\n\nTotal Amount: {$scrubbed['total_amount']}\n\nPaying By: {$scrubbed['payment_option']}\n\n\n\nOTHER INFORMATION\n\nNotes: {$scrubbed['notes']}\n\nAccept Conditions: {$scrubbed['accept_conditions']}\n\n"; $body = wordwrap($body, 90); // Send the email: mail('OUR EMAIL ADDRESS REMOVED HERE', 'Online Booking Form', $body, "From: {$scrubbed['email']}"); // Print a message: echo 'OUR THANK YOU MESSAGE REMOVED HERE'; // Clear $_POST (so that the form's not sticky): $_POST = array(); } } // End of main isset() IF. ?> <?php if (isset($_POST['submitted'])) { if (empty($scrubbed['accept_conditions'])) { echo '<p class="make_red"><span class="highlighted_text">Please tick the "I accept" box at the bottom of the form to agree to booking conditions</span></p>'; } } ?>
  3. Thanks for the pointer - I've done that now. Thank you - I see how that there's the <h1> before the php runs - I assume that's the issue then. I'll see if I can reorder things!
  4. Hi Antonio, thank you for your message. At the moment I'm using exactly the test script 12.1 from the book, but simply replacing: echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>'; with header("Location: thankyou.htm"); [not sure if I also need exit(); afterwards but this doesn't seem to help] The error gives line 53, which is the line containing header("Location: thankyou.htm"); --- So the entire page code is: <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Contact Me</title> </head> <body> <h1>Contact Me</h1> <?php # Script 12.1 - email.php #2 // Check for form submission: if (isset($_POST['submitted'])) { /* The function takes one argument: a string. * The function returns a clean version of the string. * The clean version may be either an empty string or * just the removal of all newline characters. */ function spam_scrubber($value) { // List of very bad values: $very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:'); // If any of the very bad strings are in // the submitted value, return an empty string: foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ''; } // Replace any newline characters with spaces: $value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value); // Return the value: return trim($value); } // End of spam_scrubber() function. // Clean the form data: $scrubbed = array_map('spam_scrubber', $_POST); // Minimal form validation: if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['comments']) ) { // Create the body: $body = "Name: {$scrubbed['name']}\n\nComments: {$scrubbed['comments']}"; $body = wordwrap($body, 70); // Send the email: mail('example@example.com', 'Contact Form Submission', $body, "From: {$scrubbed['email']}"); // Print a message: header("Location: thankyou.htm"); // Clear $_POST (so that the form's not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; color: #C00">Please fill out the form completely.</p>'; } } // End of main isset() IF. ?> <p>Please fill out this form to contact me.</p> <form action="test-email-fresh.php" method="post"> <p>Name: <input type="text" name="name" size="30" maxlength="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p> <p><input type="submit" name="submit" value="Send!" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> --- Am I doing something silly?
  5. I am working with the "secure" version of contact form script 12.1 described in "Chapter 12 - Security Methods" (pg. 365) but would like to modify this so that rather than simply printing a thank you message, the user is redirected to a thank you page. I have tried replacing the given script: // Minimal form validation: if (!empty($scrubbed['email'])) { // Create the body: $body = "Name: {$scrubbed['name']}\n\nComments: {$scrubbed['comments']}"; $body = wordwrap($body, 70); // Send the email: mail('XXX@XXX', 'Contact Form Submission', $body, "From: {$scrubbed['email']}"); // Print a message: echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>'; // Clear $_POST (so that the form's not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; color: #C00">Please enter a valid email address.</p>'; } with modified: // Minimal form validation: if (!empty($scrubbed['email'])) { // Create the body: $body = "Name: {$scrubbed['name']}\n\nComments: {$scrubbed['comments']}"; $body = wordwrap($body, 70); // Send the email: mail('XXX@XXX', 'Contact Form Submission', $body, "From: {$scrubbed['email']}"); // Redirect to thank you page: header("Location: thankyou.htm"); exit(); // Clear $_POST (so that the form's not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; color: #C00">Please enter a valid email address.</p>'; } ..but get the error: Warning: Cannot modify header information - headers already sent by (output started at /websites..... Reading about this, it seems nothing can be sent to the browser before header is used. But however I try to move things around, I cannot get this to work. Could you advise how/where this redirect should be used within this script? Thank you.
×
×
  • Create New...