I have a registration website that collects name, email, address etc from a form. The php code that processes the form validates the inputs and creates sessions for the variables so I can use them on a confirmation page once the form is submitted.
I have used a shell script .. eg exec ("/usr/local/bin/php emailsend.php >/dev/null &");
on the confirmation page that runs a php file in the background once the confirmation page has loaded in the browser. This php file sends a "thank you for registering" email as well as sending a copy to us. (It runs in the background because it has a delay built in before it sends the emails -if I put the code directly onto the confirmation page then that page would not be able to load fully until the delay was finished) I want to personalise the thank you email with the persons name. However for some reason the session variables that are created by the form submission won't print on the thank you email. It keeps coming up blank where the persons name should be. Is there a reason why session variables that I can access and write to any other page on the site won't show up on a page that hasn't been loaded into a browser but simply runs in the background and sends out emails?
I have posted the code for the emailsend.php page below with the name greeting in red. Can anyone let me know whether I'm coding this wrong in the way I'm trying to access the username session variable. Any help would be appreciated.
$email = $_REQUEST['access_login'] ;
//define the receiver of the email
$to = "<$email>";
$to2 = "email@example.com";
//define the subject of the email
$subject = 'Welcome to our website';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: reply@emailaddress\r\nReply-To: firstname.lastname@example.org";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
What does that emailsend.php file do actually? Why do you need to run that script in the background in the confirmation page. Quite strange! Can we try to avoid the use of exec? If you say the purpose of that, someone can present you a solution so that you don't need to use exec.
Thanks for the help guys. It's not my preference for it to be like this but it's not just a simple feedback form. It has to do a whole bunch of things all at once that normally shouldn't go together...but that's the brief I've been given so I'm going to piece it together roughly and get it working and then simplify it down the track.
Actually what I mean is, what are the things that are to be done before/after that delay? If they are manageable with some other way then we all can think of it.
Originally Posted by hawker2
It has to do a whole bunch of things all at once that normally shouldn't go together...but that's the brief I've been given so I'm going to piece it together roughly and get it working and then simplify it down the track.
So you also don't know now that what are the tasks/things to be done before that delay or with that delay in that script? Are those things to be done at the time of this email sending or they can be done periodically with some schedules as has suggested before? I am quite confused what the delay is for. Did OP mention about it?