I’m using the code below to send an email to my address alerting me of a new user sign up:
<?php
$errors = '';
$myemail = 'name@mydomain.com';
if (empty($_POST['email']) || empty($_POST['email']) || empty($_POST['email'])) {
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address
)) {
$errors .= "\n Error: Invalid email address";
}
if (empty($errors)) {
$to = $myemail;
$email_subject = "Invitation Request: $email_address";
$email_body = "has received a new invitation request. " .
"\n Email: $email_address";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to, $email_subject, $email_body, $headers);
//redirect to the 'thank you' page
}
?>
Currently it redirects users to a new page but instead I want it to allow for a javascript pop-up success/fail message much like those used in modern websites.
Here is the message code (CSS and Javascript):
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<style type="text/css">
/* Status Message */
.message {
display: none;
margin: 0 0 13px 0;
padding: 13px 13px 13px 52px;
background: url('icon_check.gif') left no-repeat #EFA;
background-position: 13px 5px;
border: solid 1px #BD8; '
width: 300px;
}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#Button1").click(function(event){
$(".message").show();
$(".message").fadeOut(2500);
});
});
</script>
and here’s the html for the success message:
<div class="message">Your Invitation Request Has Been Received!</div>
Is it possible to do this? I’ve looked in several places for the answer over the past two days and I can’t seem to change the right thing. Any help would be appreciated.
With your current setup, the best way to do this would be to redirect back to the signup page with a query string that tells the page to open the window from there.
and in the JS
Also, I recommend using filter_var to validate emails.