I have this code when I submit a form:

<?php
  $email = $_REQUEST['email'] ;
  $name = $_REQUEST['name'] ;

  mail( "Saamon@live.com", "Website Opt In Form Results",
    $message, "From: $email" );
  header( "Location: index.html" );
?>

On the header location part, how can I make a popup window appear instead of a new page?

Thanks

<?php
        $email = $_REQUEST['email'] ;
        $name = $_REQUEST['name'] ;
 
      mail( "Saamon@live.com", "Website Opt In Form Results",

      $message, "From: $email" );
echo"<script language='javascript'>newwindow('index.html');</script>";
     
 
      ?>

and javascript code in header of page

<script language="javascript">

function newwindow(url)
{
var url = url;
window.open(url,'MyWin','resizable=yes,scrollbars=yes,width=200,height=200,left=400,top=250');
} 

</script>

try like this

Great, I'll try, does the java script go in the php page? or the html?

I have this code when I submit a form:

<?php
  $email = $_REQUEST['email'] ;
  $name = $_REQUEST['name'] ;

  mail( "Saamon@live.com", "Website Opt In Form Results",
    $message, "From: $email" );
  header( "Location: index.html" );
?>

On the header location part, how can I make a popup window appear instead of a new page?

Thanks

Instead of header you can end the php code and put something like following,
<script language="javascript">
window.open("index.html");
</script>
But If you are expecting a something like a div popup then you have to use an absolute <div> like lightbox. Hope this will help !

Great, I'll try, does the java script go in the php page? or the html?

use it in php and html, it will work . i tried it in php.

Didn't work, just took me to the "email.php" page rather than just popping up with a message.

post your code . explain what do you want . you want popup the page or popup the message.

I would like a message to popup. I posted the PHP code above - this php code is on a separate page to my html.

This is my form:

<form name="form1"  method="post" action="email.php">
		  <p><span class="title">First Name</span><br>
		    <label>
		      <input name="name" type="text" id="name" size="25">
		    </label>
		    <br><Br>
		    <span class="title">Email</span><br>
		    <label>
		      <input name="email" type="text" id="email" size="25">
	        </label>
		    <br><br>
		    <label>
		      <input type="submit" name="button" id="button" value="Submit" onclick="thanksDiv()">
	        </label>
	      </p>
</form>

if you want message to popup use alert() function write your message .

<?php
      $email = $_REQUEST['email'] ;
        $name = $_REQUEST['name'] ;
             mail( "Saamon@live.com", "Website Opt In Form Results",
      $message, "From: $email" );

      echo"<script language='javascript'>alert('your message');</script>";
 
      ?>

if your message if too long to display.
write your message in separate file name it as msg.php

<?php

      $email = $_REQUEST['email'] ;

      $name = $_REQUEST['name'] ;
 
      mail( "Saamon@live.com", "Website Opt In Form Results",
 
       

      $message, "From: $email" );
 
      echo"<script language='javascript'>newwindow('msg.php');</script>";
 
      ?>

write javascript code in same file(which is having newwindow() function);

That still just takes me to the email.php page which is blank

did you get message or not. and remove header("location.html");
and in form you set action="email.php"; remove it

one more
in the submit button you have onclick(); function remove it.

see this;

<?php
if($_POST['button']=="Submit")
{
      $email = $_REQUEST['email'] ;

      $name = $_REQUEST['name'] ;
  
      mail( "Saamon@live.com", "Website Opt In Form Results",
 
      $message, "From: $email" );
  
      echo"<script language='javascript'>alert('your message');</script>";
	  }
        ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
       <form name="form1" method="post" action="">
      <p><span class="title">First Name</span><br>
       <label>
       <input name="name" type="text" id="name" size="25">
      </label>
        <br><Br>
        <span class="title">Email</span><br>
      <label>
      <input name="email" type="text" id="email" size="25">
      </label>
      <br><br>
      <label>
       <input type="submit" name="button" id="button" value="Submit" >
        </label>
      </p>
        </form>
</body>
</html>

The box is popping up but on top of the PHP page rather than the original HTML page...

your php page

<?php

if($_POST['button']=="Submit")
{

$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
mail( "Saamon@live.com", "Website Opt In Form Results",

$message, "From: $email" );
header("location:yourhtmlfilename.html?success=1")

}
?>

in the html page

<body onload="javascript: var hu = window.location.search.substring(1);
ft = hu.split('='); var g=ft[1]; if(g==1){alert('your message');}">
</body>

the message alert box displayed in your html file.

That still just takes me to the email.php page which is blank

I know I understood what is your problem,

You are calling a js function on the submit button, If you want a js function execute before form submission, you need to call that function on the form, like this

<form method="post" action="actionpage.php" onSubmit="jsfunction();">

remove function on submit button, it won't works for you
in your jsfunction, just add an alert box.

Now your code will work.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.