Solved

Help with a bit of PHP coding please

Posted on 2006-06-09
12
265 Views
Last Modified: 2006-11-18
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
Comment
Question by:pauldownham
  • 7
  • 5
12 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 16869463
Insert these two lines there, substituting the link with yours:
sleep(2);
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
0
 

Author Comment

by:pauldownham
ID: 16869555
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
 
LVL 30

Accepted Solution

by:
callrs earned 125 total points
ID: 16869651
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
 
LVL 30

Expert Comment

by:callrs
ID: 16869682
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
 
LVL 30

Expert Comment

by:callrs
ID: 16869780
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
 

Author Comment

by:pauldownham
ID: 16869907
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 30

Expert Comment

by:callrs
ID: 16870254
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
 
LVL 30

Expert Comment

by:callrs
ID: 16870267
I may not be back for another 12 hours...gotta do yard work etc.
0
 

Author Comment

by:pauldownham
ID: 16870425
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
 

Author Comment

by:pauldownham
ID: 16870558
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
 
LVL 30

Expert Comment

by:callrs
ID: 16875968
How'd it go?
parent.location.href is for parent of the current document
top.location.href is for the top document
0
 

Author Comment

by:pauldownham
ID: 16877389
It seems fine .. so many thanks, and here's the points.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
API Soap Calls 4 89
Does video get better conversion rates? 2 29
Materializecss - Different Behaviors in Browser's 1 20
Not seen Link button 5 15
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Read about why website design really matters in today's demanding market.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now