Link to home
Start Free TrialLog in
Avatar of pauldownham
pauldownham

asked on

Help with a bit of PHP coding please

I know nothing about PHP, but am running a small piece of PHP code that someone else wrote that submits a web visitor's request to our email address .. which works fine.

What I need now is extra code so that after successful completion the user gets to see the OK message for a second or two, and is then redirected to a new URL.

The relevant existing lines are:

// send emails
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// report successful  
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=mailok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=mailnotok.htm\">";
}

and what I need is the correct way to say this:

// send emails
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// report successful  
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=mailok.htm\">";
 
  PAUSE FOR A SHORT TIME
  GOTO HTTP://WWW. ....

  }
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=mailnotok.htm\">";
}


Thanks
Avatar of callrs
callrs

Insert these two lines there, substituting the link with yours:
sleep(2);
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
Avatar of pauldownham

ASKER

Callrs,

Thanks ... done this:

// report successful  
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=mailok.htm\">";
  sleep(2);
  header( 'Location: http://www.MYSITE.co.uk/shop' ) ;
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=mailnotok.htm\">";
}

and what happens is that the displaying of the MAILOK message is delayed by 2 seconds, and then nothing else ?

help!

ASKER CERTIFIED SOLUTION
Avatar of callrs
callrs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correction
function redirect() {setTimeout("location.href='http://www.MYSITE.co.uk/shop''", 2000); }
should be
function redirect() {setTimeout("location.href='http://www.MYSITE.co.uk/shop'", 2000); }
(The extra single quote is an error, sry)
Works now  :)
print "<meta http-equiv=\"refresh\" content=\"0;URL=<?php echo $to; ?>\">";
or this
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.MYSITE.co.uk/shop\">";
should also work in the second solution, in place of this line:
header('Location: '. $to);

Experiment with all three of these possibilities & please let me know how it goes. Thanks! :)
Wow  ... nearly there!

I've used your No 1 idea ... and what happens is perfect, except for two final issues ...

The first problem is that mailok.htm is only a message, so opens in a tiny little window with no scrollbars or resize, and its in here that the shop page opens (so you only see a fraction of the top corner).

The second issue is that the previous window where the visitor wrote their message is also still visible.

I suppose what I should have asked for is that the new URL be treated as if an entirely new action?

Cheers

Paul


One resolution is to have malok.htm open in the 1st window. That way the user's message window disappears & the shop page will open in the original full window.
Do you need mailok.htm to open in a tiny window?

But I can get it working even if you want mailok to open in separate window.
BUT...I'm confused: what is making mailok.htm open in a new window? Your php file is not doing it, from the code you've given here.
E.g. The line
<META HTTP-EQUIV="Refresh" Content= "0; URL=http://google.com">
Opens google.com on the SAME PAGE, not in a tiny different page...
A script in the mailok.htm may be doing the separate window through a re-direct? But I think there's something in your php code that you didn't post here?

I may not be back for another 12 hours...gotta do yard work etc.
The php code manipulates messages in the tiny window ... which is actually an IFRAME  ... and puts up messages like telling the user that his missed out an answer or got a badly formatted email address etc.  The mailok is the last message after successful completion, and thats when we need to move things on (at the moment they have to use the X on the window).

So we kindof need a code that says close the existing windows and open a the new shop one.

Good luck in the yard!
OK ... I've been clicking around this site some more and found you can say "parent.location.href" to make the new location operate within the parent window .... which seems to do the trick!

I'll just test it for real, and be back with the points...

How'd it go?
parent.location.href is for parent of the current document
top.location.href is for the top document
It seems fine .. so many thanks, and here's the points.