[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

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
0
pauldownham
Asked:
pauldownham
  • 7
  • 5
1 Solution
 
callrsCommented:
Insert these two lines there, substituting the link with yours:
sleep(2);
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
0
 
pauldownhamAuthor Commented:
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!

0
 
callrsCommented:
Revised: (I forget the "exit", see http://www.faqts.com/knowledge_base/view.phtml/aid/4127/fid/60)
sleep(2);
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
exit;
-------
But I'm guessing that that won't work, because the meta tag takes you to mailok.htm, a completely different page that then would have control (and so your php routine would lose control -- my theory)
So Here are two solutions, the 1st which uses Javascript & I've tried & it works:
USE ONE OF THE SOLUTIONS, NOT BOTH:
1) ===============
EDIT YOUR MAILOK.HTM file to include this these 3 lines within the <HEAD>...</HEAD> tags (add these tags at the top if they aren't there)
MAKE SURE YOU INSERT THEM O U T S I D E  OTHER POSSIBLE <SCRIPT>...</SCRIPT>, OR <?php...?>, ETC., TAGS
--------------------------------------
<script type="text/javascript">
function redirect() {setTimeout("location.href='http://www.MYSITE.co.uk/shop''", 2000); }
</script>
--------------------
NOW: modify your <BODY> tag to include this "onload" statement:
<body onLoad="redirect();">

2)=========================
The second solution uses PHP which I've not tried (I don't have PHP installed yet, sorry), but I've done the research & it should work:
ADD THESE LINES TO THE END OF YOUR MAILOK.HTM FILE, JUST BEFORE THE </HTML> closing tag:
  <?php
    sleep(2);
    $to = 'http://www.MYSITE.co.uk/shop'';
    header('Location: '. $to);
    exit;
  ?>

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
callrsCommented:
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  :)
0
 
callrsCommented:
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! :)
0
 
pauldownhamAuthor Commented:
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


0
 
callrsCommented:
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?

0
 
callrsCommented:
I may not be back for another 12 hours...gotta do yard work etc.
0
 
pauldownhamAuthor Commented:
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!
0
 
pauldownhamAuthor Commented:
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...

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now