Jump to content
Larry Ullman's Book Forums

Recommended Posts

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>';
                    }
                }
              ?>
Link to comment
Share on other sites

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);
Link to comment
Share on other sites

 Share

×
×
  • Create New...