Solved

Help with a bit of PHP coding please

Posted on 2006-06-09
12
264 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 30

Expert Comment

by:callrs
Comment Utility
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
Comment Utility
I may not be back for another 12 hours...gotta do yard work etc.
0
 

Author Comment

by:pauldownham
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It seems fine .. so many thanks, and here's the points.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Read about why website design really matters in today's demanding market.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

763 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

14 Experts available now in Live!

Get 1:1 Help Now