Jump to content

Recommended Posts

I hope someone can help. I'm a volunteer for a charity and have been passed a php script from another branch of the charity for a contact form that registers people for an event.  It works.

 

However, I've been asked by my branch if the web page that is shown and the email that gets sent to people on successful registration can be slightly different for members and non-members.  I have no idea how to do this!

 

This is the script as it stands sending one email:

 

<?php

 

// Populate variables  ENTER YOUR OWN EMAIL ADDRESS BELOW

$to = "gan@midsussexnct.org.uk";

$subject = "Spring 2010 Nearly New Sale Seller Registration";

$from = $_REQUEST['email'];

 

$nctmember = $_REQUEST['nctmember'];

$membno = $_REQUEST['membno'];

$firstname = $_REQUEST['firstname'];

$surname = $_REQUEST['surname'];

$address1 = $_REQUEST['address1'];

$address2 = $_REQUEST['address2'];

$town = $_REQUEST['town'];

$town2 = $_REQUEST['town2'];

$county = $_REQUEST['county'];

$postcode = $_REQUEST['postcode'];

$tel = $_REQUEST['tel'];

$headers = "From: $from";

$email = $_REQUEST['email'];

$filename = "nns_registration.csv";

$membership = "nctmembership.csv";

$timefile = "timediff.csv";

 

$vendorno = count(file($filename));

$memberno = count(file($membership));

 

// Define array

$fields = array();

$fields{"membno"} = "membno";

$fields{"firstname"} = "firstname";

$fields{"surname"} = "surname";

$fields{"address1"} = "address1";

$fields{"address2"} = "address2";

$fields{"town"} = "town";

$fields{"town2"} = "town (if other)";

$fields{"county"} = "county";

$fields{"postcode"} = "postcode";

$fields{"tel"} = "tel";

$fields{"email"} = "email";

 

//Function to check if we have a valid membership number

function validate_member( $membno )

{  

    global $membership;

global $memberno;

 

$row2 = 1;

    $member = 'no';

  $open2 = fopen($membership,"r");

  for ( $row2 = 1; $row2 <= $memberno; $row2 += 1)

    {

        $data2 = fgetcsv($open2, 1000); 

        if ($data2[0] == $membno) 

    {

          $member = 'yes';

          } 

    }

return $member;

}

 

// Function to email successful vendor  CHANGE THE AUTOREPLY ADDRESS BELOW TO YOUR OWN MAIL DOMAIN

function success_register($body)

{

global $vendorno;

global $fields;

global $to;

global $subject;

global $headers;

global $from;

global $firstnametidy;

 

$headers2 = "From: autoreply@midsussexnct.org.uk";

$subject2 = "Spring 2010 Nearly New Sale Seller Registration";

$autoreply = "Dear $firstnametidy

 

THIS IS AN AUTOMATED EMAIL, PLEASE DO NOT RESPOND TO THIS ADDRESS.

 

Thank you for registering to sell at our Spring 2010 Nearly New Sale.

 

Thank you for supporting our Spring 2010 Nearly New Sale.";

 

$send = mail($to, $subject, $body, $headers);

$send2 = mail($from, $subject2, $autoreply, $headers2);

 

return $send2;

}

 

 

//

//

// MAIN PROGRAM CODE AND PROCESS FLOW STARTS HERE

//

//

 

// Set Flag used to trace if errors have been detected

$ErrorFlag = 'Okay';

 

// Check to see if date is correct to register as non-member

// Remember $non_member_reg_date and time() are 'timestamp' values (number of seconds since Jan 1 1970)

// Hence if $non_member_reg_date is bigger than time(), $non_member_reg_date is in the future (more seconds after Jan 1 1970 that current time.)

if ( ($nctmember == 'no') && ($non_member_reg_date > $real_time ) )

{

header("Location: http://www.midsussexnct.org.uk/nns_tooearly.html");

$ErrorFlag = 'Error';

}

 

// Check to see if 'membership' radio button is set to YES but no membership number has been given

if ( ($nctmember == 'yes') && ($membno == '') )

{print "You have stated you are an NCT Mid Sussex branch member but have not provided your NCT membership number. Please go back using the Back button in your browser and enter your NCT membership number.  You may find this on your NCT membership card.<br>\n";

$ErrorFlag = 'Error';

}

 

// Test for blank fields

validate_blank($firstname, "entered your first name");

validate_blank($surname, "entered your surname");

validate_blank($address1, "entered the first line of your address");

validate_blank($town, "entered your postal town, having selected 'other' from the list");

validate_blank($postcode, "entered your full postcode");

validate_blank($tel, "entered your telephone number");

validate_blank($email, "entered your email address");

 

// Test more complex conditions

if (ereg('[^A-Za-z0-9 ]', $postcode))

{ print "The postcode entered contains characters other than letters and numbers, please go back using the Back button in your browser and try again.<br>\n";

$ErrorFlag = 'Error';

}

if (ereg('[^0-9 ]', $membno))

  {print "The NCT membership number entered contains characters other than numbers, please go back using the Back button in your browser and try again.<br>\n";

  $ErrorFlag = 'Error';

  }

if (ereg('[^0-9 ]', $tel))

  {print "The telephone number entered contains characters other than numbers, please go back using the Back button in your browser and try again.<br>\n";

  $ErrorFlag = 'Error';

  }

 

// Check to see if we have found any dodgy fields, if we have, exit now

if ($ErrorFlag == 'Error')

    {

    exit();

    }

 

 

// If we continue past here we know all the fields are valid

 

 

// Check for duplicate entry in vendor file

if ( validate_duplicate( $email , $membno ) == 'yes' )

{

header("Location: http://www.midsussexnct.org.uk/nns_duplicate.html");

exit();

}

 

 

// Check to see if we have a valid membership number

if ( $nctmember == 'yes' )

{

if ( validate_member($membno) == 'no' )

{

    header("Location: http://www.midsussexnct.org.uk/nns_nonmember.html");

exit();

}

}

 

 

// To get here means all validation checks passed, we just need to check if there are spaces available

 

 

// Check to see if we have filled all vendor places yet  NB CHANGE NUMBER FOR LIVE SALE, 20 ONLY FOR TEST

$vendorno = count(file($filename));

if ($vendorno < '6')

{

// Successful registration - build data for CSV file record

$cr = "\n";

$loaddata .= $vendorno . '#' . $membno . '#' . $firstnametidy . '#' . $surnametidy . '#' . $address1tidy . '#' . $address2tidy . '#' . $town . '#' . $county . '#' . $postcodetidy . '#' . $tel . '#' . $email . $cr;

 

// Add record to our CSV file

$fp = fopen($filename,"a"); // $fp is now the file pointer to file $filename

if($fp)

{

fwrite($fp,$loaddata);    //    Write information to the file

fclose($fp);  //    Close the file

}

else

{

echo " Error saving file.";

}

 

// Generate and send email to vendor coordinator

// This returns original user input with no tidying up of case etc.

// This is to ensure we retain an exact copy of the form data the user entered

$body = "We have received the following Seller Registration information:\n\n vendor registration number = $vendorno \n";

foreach($fields as $a => $b)

{

$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);

}

if ( success_register( $body ) )

{

header("Location: http://www.midsussexnct.org.uk/nns_confirmation.html");

}

else

{

print "We encountered an error sending your mail, please notify gan@midsussexnct.org.uk";

}

 

}

else

{

// All vendor slots filled so need to add record to waiting list CSV file

$filename2 = "nns_waitinglist.csv";

$cr = "\n";

$emailtxt .=  $membno . '#' . $firstnametidy . '#' . $surnametidy . '#' . $address1tidy . '#' . $address2tidy . '#' . $town . '#' . $county . '#' . $postcodetidy . '#' . $tel . '#' . $email . $cr;

$fp = fopen($filename2,"a"); // $fp is now the file pointer to file $filename

if($fp)

{

    fwrite($fp,$emailtxt);    //    Write information to the file

    fclose($fp);  //    Close the file

    }

else

{

    echo " Error saving file.";

}

 

// Generate and send email

$body = "We have received the following Seller Registration information for the Seller Waiting List:\n\n";

foreach($fields as $a => $b)

{

$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);

}

if( waitlist_register( $body ) )

{

header("Location: http://www.midsussexnct.org.uk/nns_refusal.html");

}

else

{

print "We encountered an error sending your mail, please notify gan@midsussexnct.org.uk";

}

 

}

//

// End of program code

//

 

 

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

 

// $filename3 = "PaulOutput.txt";

//$cr = "\n";

// $txt =  $nm . '#' . $membno . '#' . $data2[0] . '#' . $data2[1] . '#' . $data2[2] . $cr ; 

//$fp = fopen($filename3,"a"); // $fp is now the file pointer to file $filename3

//if($fp)

  //{

  //fwrite($fp,$txt);    //    Write information to the file

        //fclose($fp);  //    Close the file

      //}

//else

  //{

    //echo " Error saving file.";

//}

 

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

//  CAN DELETE ALL THE STUFF BETWEEN THESE COMMENT LINES

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/189096-email-response-dependent-on-form-entry/
Share on other sites

This may be difficult unless the user/member is logged in. If they are logged in, you could have the script populate the form for them. If they are not logged in, you could check the database for a record that matches, but your results may vary based on the sql used.

 

Going back to if they are logged in, it should be easy enough to check that, and then use an if statement to send an email, or send the other email if not logged in.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.