Jump to content

Redirect after Form completed


Landslyde
Go to solution Solved by Monkuar,

Recommended Posts

After 13 years of laboring over this, I finally got my form fixed today. Just two issues left:

 

1) Upon form submission, an email is sent out to the user. How do I redirect them to a Thank-You page so they don't have to stare at the Registration screen while the email is being sent out, as this seems to be a little slow.

 

2) In the body of these emails is a link to click to go to the Login screen. This works fine. However, I also provide them with two email addresses. How do I make them clickable (like the web link)?

$message = $fname.":\n\n"."Thank you for subscribing to my services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nwww.mySite.com/login.php\n\n\n\nTech Support: techsupport@mysite.com\nSales: sales@mysite.com";
    

Thanks for your help,

Landslyde

 

PS: Just kidding abt the 13 years...only took 12 :D

Edited by Landslyde
Link to comment
Share on other sites

I send my entire script because I may have something in the wrong place concerning the email and redirect.

<?php
$fnameErr = $lnameErr = $emailErr = $unameErr = $pwd1Err = $pwd2Err = "";
$fname = $lname = $email = $uname = $pwd1 = $pwd2 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["fname"])) {
    $fnameErr = "* First name is required";
  } else {
    $fname = test_input($_POST["fname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$fname)) {
      $fnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["lname"])) {
    $lnameErr = "* Last name is required";
  } else {
    $lname = test_input($_POST["lname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$lname)) {
      $lnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["email"])) {
    $emailErr = "* Email is required";
  } else {
    $email = test_input($_POST["email"]);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "* Invalid email format";
    }
  }
  if (empty($_POST["uname"])) {
    $unameErr = "* Username is required";
  } else {
    $uname = test_input($_POST["uname"]);
    if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) {
      $unameErr = "* Only letters and numerals are allowed";
    }
  }
  if (empty($_POST["pwd1"])) {
    $pwd1Err = "* Password is required";
  } else {
    $pwd1 = test_input($_POST["pwd1"]);
  }
  if (empty($_POST["pwd2"])) {
    $pwd2Err = "* Password confirmation is required";
  } else {
    $pwd2 = test_input($_POST["pwd2"]);
    if($pwd1 != $pwd2) {
    	$pwd2Err = "* Passwords do not match";
  }
}
    $to = $_POST['email']; // this is your Email address
    $from = "verify@mysite.com"; // this is the sender's Email address
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $subject = "Form submission";
    $message = $fname . ":\n\n" . "Thank you for subscribing to my services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nhttp:www.mysite.com/login.php\n\n\n\nTech Support: techsupport@mysite.com\nSales: sales@mysite.com";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    header("Location: www.mysite.com/thankyou.html"); // I put this in but it won't redirect until the mail
    						      // sends...and that's sorta slow.
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

Am I doing something wrong?

 

Landslyde

Link to comment
Share on other sites

If you would turn on php error checking (see my sign.) you would see the reason that you don't see anything. It's not the email holding you up. It is the error you are generating.

 

I'm on Linux and use Bluefish editor. When I run this php file, I have to send it to the localhost. I just added your "sign" information and ran the file again. I see no errors. Nothing advises me of an error. What error do you see?

 

Landslyde

Edited by Landslyde
Link to comment
Share on other sites

sign? sign=signature. Did you add those lines to the beginning of your php code? Could we see it?

 

Yes, of course "we" can see it...

<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
$fnameErr = $lnameErr = $emailErr = $unameErr = $pwd1Err = $pwd2Err = "";
$fname = $lname = $email = $uname = $pwd1 = $pwd2 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["fname"])) {
    $fnameErr = "* First name is required";
  } else {
    $fname = test_input($_POST["fname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$fname)) {
      $fnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["lname"])) {
    $lnameErr = "* Last name is required";
  } else {
    $lname = test_input($_POST["lname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$lname)) {
      $lnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["email"])) {
    $emailErr = "* Email is required";
  } else {
    $email = test_input($_POST["email"]);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "* Invalid email format";
    }
  }
  if (empty($_POST["uname"])) {
    $unameErr = "* Username is required";
  } else {
    $uname = test_input($_POST["uname"]);
    if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) {
      $unameErr = "* Only letters and numerals are allowed";
    }
  }
  if (empty($_POST["pwd1"])) {
    $pwd1Err = "* Password is required";
  } else {
    $pwd1 = test_input($_POST["pwd1"]);
  }
  if (empty($_POST["pwd2"])) {
    $pwd2Err = "* Password confirmation is required";
  } else {
    $pwd2 = test_input($_POST["pwd2"]);
    if($pwd1 != $pwd2) {
    	$pwd2Err = "* Passwords do not match";
  }
}
    $to = $_POST['email']; // this is your Email address
    $from = "verify@dfwit.co"; // this is the sender's Email address
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $subject = "Form submission";
    $message = $fname . ":\n\n" . "Thank you for subscribing to DFW Information Technologies database services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nhttp:www.dfwit.co/index.html\n\n\n\nTech Support: techsupport@dfwit.co\nSales: sales@dfwit.co";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
    header("Location: www.dfwit.co/index.html"); // I put this in but it won't redirect until the mail
    					         // sends...and that's sorta slow.
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

Tired of whiting out my site.

Link to comment
Share on other sites

And you aren't seeing an error message?

 

The error is you cannot execute a header command once you have output something. Which you are doing right after your mail() call.

 

But I can't do the redirect before the mail call, right? I'm new to php, and that must be obvious to you by now. But I'm trying.

Link to comment
Share on other sites

Programming is a very exact science. Therefore you need to be able to clearly read your own code in order to debug it.

 

As I said above - you can't output anything prior to the header call. So - what's wrong with your code here:

 

mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
header("Location: www.dfwit.co/index.html");

Edited by ginerjm
Link to comment
Share on other sites

Programming is a very exact science. Therefore you need to be able to clearly read your own code in order to debug it.

 

As I said above - you can't output anything prior to the header call. So - what's wrong with your code here:

 

mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
header("Location: www.dfwit.co/index.html");

 

I guess I need to do away with the header call, the redirect. Right?

Link to comment
Share on other sites

Hmmm - seme to have lost my response. Trying again.

 

Tip - Why not add those tests for empty to your test function and save a whole lot of coding? Plus - why do you bother to do all the testing and not handle any errors that you find? Kind of a waste of energy, no?

Link to comment
Share on other sites

Hmmm - seme to have lost my response. Trying again.

 

Tip - Why not add those tests for empty to your test function and save a whole lot of coding? Plus - why do you bother to do all the testing and not handle any errors that you find? Kind of a waste of energy, no?

Yeah. IMHO, php should have try-catch blocks. I have your error-catching code installed in my script and still see no errors thrown. And you're right about programming being an exact science. I've been doing it since '83, but am very new to php and am skinning my knees and banging my head as I go along :D

Link to comment
Share on other sites

It does have try catch blocks. But you have written the kind of checks you neeed. You just forgot to check if you set any of them. Trick: Use an array and set a different index for each message if you have an error. Then if the array is not empty you have messages to echo. Then do a foreach loop on the array and echo out each message.

 

Back to the previous question - what's wrong with those three lines? Not the header! Again: You can't output anything prior to a header call. You send the mail. You output your message. You (attempt to) send a header. WRONG!

Link to comment
Share on other sites

Having now extracted your code and re-formatted it to read it and deciphered it, could we see the actual input form code?

 

Q1 - why does you email use the unsanitized input values in the email instead of the ones you bothered to clean?

 

Q2 - Do you ever receive the email?

 

PS - I've got 12+ years on you!

Link to comment
Share on other sites

Having now extracted your code and re-formatted it to read it and deciphered it, could we see the actual input form code?

 

Q1 - why does you email use the unsanitized input values in the email instead of the ones you bothered to clean?

 

Q2 - Do you ever receive the email?

 

PS - I've got 12+ years on you!

 

A1: My bad. I have now changed that.

 

A2: Yes

 

You started programming in '72? Amazing. Languages have come a long way since COBOL :D

 

Here is my entire page. If you find errors, do not shout at me. I loathe being shouted at.

<!DOCTYPE html>
<html>
<head>
<title>DFW Information Technologies</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="generator" content="Bluefish 2.2.5" >
<meta name="author" content="Landslyde" >
<meta name="date" content="2015-01-25T17:49:28-0600" >
<meta name="copyright" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="expires" content="0">
<link href="style/index.css" rel="stylesheet">
<!--[if lt IE 9]>
<script scr="html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->	
</head>
<body>
<h1>DFW Information Technologies</h1>
<img class="img1" src="images/blue_world.jpeg" width="225" height="225">
<div class="gradientbuttons">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="client.php">Client Area</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</div>
<?php

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');

$fnameErr = $lnameErr = $emailErr = $unameErr = $pwd1Err = $pwd2Err = "";
$fname = $lname = $email = $uname = $pwd1 = $pwd2 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["fname"])) {
    $fnameErr = "* First name is required";
  } else {
    $fname = test_input($_POST["fname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$fname)) {
      $fnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["lname"])) {
    $lnameErr = "* Last name is required";
  } else {
    $lname = test_input($_POST["lname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$lname)) {
      $lnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["email"])) {
    $emailErr = "* Email is required";
  } else {
    $email = test_input($_POST["email"]);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "* Invalid email format";
    }
  }
  if (empty($_POST["uname"])) {
    $unameErr = "* Username is required";
  } else {
    $uname = test_input($_POST["uname"]);
    if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) {
      $unameErr = "* Only letters and numerals are allowed";
    }
  }
  if (empty($_POST["pwd1"])) {
    $pwd1Err = "* Password is required";
  } else {
    $pwd1 = test_input($_POST["pwd1"]);
  }
  if (empty($_POST["pwd2"])) {
    $pwd2Err = "* Password confirmation is required";
  } else {
    $pwd2 = test_input($_POST["pwd2"]);
    if($pwd1 != $pwd2) {
    	$pwd2Err = "* Passwords do not match";
  }
}
    $to = $email; // this is your Email address
    $from = "verify@dfwit.co"; // this is the sender's Email address
    $subject = "Form submission";
    $message = $fname . ":\n\n" . "Thank you for subscribing to DFW Information Technologies database services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nhttp:www.dfwit.co/index.html\n\n\n\nTech Support: techsupport@dfwit.co\nSales: sales@dfwit.co";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
    header("Location: www.dfwit.co/index.html"); // I put this in but it won't redirect until the mail
                                                 // sends...and that's sorta slow.
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
<input type="text" name="fname" placeholder="First Name" value="<?php if (isset($_POST['fname'])) { echo $fname; } ?>">
	<span class="error"> <?php echo $fnameErr;?></span><br><br>
<input type="text" name="lname" placeholder="Last Name" value="<?php if (isset($_POST['lname'])) { echo $lname; } ?>">
	<span class="error"> <?php echo $lnameErr;?></span><br><br>
<input type="text" name="email" placeholder="E-mail Address" value="<?php if (isset($_POST['email'])) { echo $email; } ?>">
	<span class="error"> <?php echo $emailErr;?></span><br><br>
<input type="text" name="uname" placeholder="Username" value="<?php if (isset($_POST['uname'])) { echo $uname; } ?>">
	<span class="error"> <?php echo $unameErr;?></span><br><br>
<input type="password" name="pwd1" placeholder="Password" value="<?php if (isset($_POST['pwd1'])) { echo $pwd1; } ?>">
	<span class="error"> <?php echo $pwd1Err;?></span><br><br>
<input type="password" name="pwd2" placeholder="Confirm Password" value="<?php if (isset($_POST['pwd2'])) { echo $pwd2; } ?>">
	<span class="error"> <?php echo $pwd2Err;?></span><br><br>
<input type="submit" value="Submit"></button>
</form>
</body>
</html>
Link to comment
Share on other sites

Ok - form looks ok. So - getting back to the error message you should be getting. With error checking turned on, I ran your 3 lines of code and I get the expected message. Why don't you? Either you are not getting to them, or the code you are posting is not what is running. Add some echos to the code and let's see what gets output before we get to the header line.

Link to comment
Share on other sites

Hmm...I set a couple echo statements prior to the first line in the mail call and one just before the mail() line. But when I submitted the form info, it spun and spun for a minute or so, then it spewed my echoes out and finished in one swift blink of an eye. So whatever is hanging it up is doing so before it reaches the mail call. And I still see no errors. Where will they show? In my browser?

Link to comment
Share on other sites

Your code is not what you sent me. Try this:

<?php
session_start();
// ALWAYS TURN ON ERROR CHECKING DURING DEVELOPMENT!!!
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
//***********************
$fnameErr = $lnameErr = $emailErr = $unameErr = $pwd1Err = $pwd2Err = "";
$fname = $lname = $email = $uname = $pwd1 = $pwd2 = "";
// turn off error indicator
$errors = false;
//*****************************
// check if we have a POST or not.
if ($_SERVER["REQUEST_METHOD"] <> "POST")
{
	displaypage();
	exit();
}
else
{
	// handle the inputs now.
	if (empty($_POST["fname"]))
	{
		// turn on error flag
		$errors = true;
		$fnameErr = "* First name is required";
	}
	else
	{
		$fname = test_input($_POST["fname"]);
		if (!preg_match("/^[a-zA-Z]*$/",$fname))
		{
			$errors = true;
			$fnameErr = "* Only letters are allowed";
		}
	}
	if (empty($_POST["lname"]))
	{
		$lnameErr = "* Last name is required";
		$errors = true;
	}
	else
	{
		$lname = test_input($_POST["lname"]);
		if (!preg_match("/^[a-zA-Z]*$/",$lname))
		{
			$lnameErr = "* Only letters are allowed";
			$errors = true;
		}
	}
	if (empty($_POST["email"]))
	{
		$emailErr = "* Email is required";
		$errors = true;
	}
	else
	{
		$email = test_input($_POST["email"]);
		if (!filter_var($email, FILTER_VALIDATE_EMAIL))
		{
			$emailErr = "* Invalid email format";
			$errors = true;
		}
	}
	if (empty($_POST["uname"]))
	{
		$unameErr = "* Username is required";
		$errors = true;
	}
	else
	{
		$uname = test_input($_POST["uname"]);
		if (!preg_match("/^[a-zA-Z0-9]*$/",$uname))
		{
			$unameErr = "* Only letters and numerals are allowed";
			$errors = true;
		}
	}
	if (empty($_POST["pwd1"]))
	{
		$pwd1Err = "* Password is required";
		$errors = true;
	}
	else
	{
		$pwd1 = test_input($_POST["pwd1"]);
	}
	if (empty($_POST["pwd2"]))
	{
		$pwd2Err = "* Password confirmation is required";
		$errors = true;
	}
	else
	{
		$pwd2 = test_input($_POST["pwd2"]);
		if($pwd1 != $pwd2)
		{
			$pwd2Err = "* Passwords do not match";
			$errors = true;
		}
	}
	// are there any errors?
	if ($errors == false)
	{
		$to = $_POST['email']; // this is your Email address
		$from = "verify@dfwit.co"; // this is the sender's Email address
		$fname = $_POST['fname'];
		$lname = $_POST['lname'];
		$subject = "Form submission";
		$message = $fname . ":\n\n" . "Thank you for subscribing to DFW Information Technologies database services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nhttp:www.dfwit.co/index.html\n\n\n\nTech Support: techsupport@dfwit.co\nSales: sales@dfwit.co";
		$headers = "From:" . $from;
		mail($to,$subject,$message,$headers);
		echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
		header("Location: www.dfwit.co/index.html"); // I put this in but it won't redirect until the mail
				 // sends...and that's sorta slow.
	}
	else
	{
		displaypage();
		exit();
	}
}
function test_input($data)
{
	$data = trim($data);
	$data = stripslashes($data);
	$data = htmlspecialchars($data);
	return $data;
}
function displaypage()
{
	global $fname,$fnameErr,$lname,$lnameErr,$email,$emailErr,$uname,$unameErr,$pwd1,$pwd1Err,$pwd2,$pwd2Err;
	$action = htmlentities($_SERVER['PHP_SELF']);
	$code=<<<heredocs
	<form method="post" action="$action">
	<input type="text" name="fname" placeholder="First Name" value="$fname">
	<span class="error">$fnameErr</span><br><br>
	<input type="text" name="lname" placeholder="Last Name" value="$lname">
	<span class="error">$lnameErr</span><br><br>
	<input type="text" name="email" placeholder="E-mail Address" value="$email">
	<span class="error">$emailErr</span><br><br>
	<input type="text" name="uname" placeholder="Username" value="$uname">
	<span class="error">$unameErr</span><br><br>
	<input type="password" name="pwd1" placeholder="Password" value="$pwd1">
	<span class="error">$pwd1Err</span><br><br>
	<input type="password" name="pwd2" placeholder="Confirm Password" value="$pwd2">
	<span class="error">$pwd2Err</span><br><br>
	<input type="submit" value="Submit">
	</button>
	</form>
	</body>
	</html>
heredocs;
	echo $code;
}
Please run this - it gives me the error message every time. Of course you should have fixed that by now.
Link to comment
Share on other sites

  • Solution

Your issue is not having error checking.

 

Here is your new code:

 

<!DOCTYPE html>
<html>
<head>
<title>DFW Information Technologies</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="generator" content="Bluefish 2.2.5" >
<meta name="author" content="Landslyde" >
<meta name="date" content="2015-01-25T17:49:28-0600" >
<meta name="copyright" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="expires" content="0">
<link href="style/index.css" rel="stylesheet">
<!--[if lt IE 9]>
<script scr="html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->	
</head>
<body>
<h1>DFW Information Technologies</h1>
<img class="img1" src="images/blue_world.jpeg" width="225" height="225">
<div class="gradientbuttons">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="client.php">Client Area</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</div>
<?php

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');

$fnameErr = $lnameErr = $emailErr = $unameErr = $pwd1Err = $pwd2Err = "";
$fname = $lname = $email = $uname = $pwd1 = $pwd2 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["fname"])) {
    $fnameErr = "* First name is required";
  } else {
    $fname = test_input($_POST["fname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$fname)) {
      $fnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["lname"])) {
    $lnameErr = "* Last name is required";
  } else {
    $lname = test_input($_POST["lname"]);
    if (!preg_match("/^[a-zA-Z]*$/",$lname)) {
      $lnameErr = "* Only letters are allowed";
    }
  }
  if (empty($_POST["email"])) {
    $emailErr = "* Email is required";
  } else {
    $email = test_input($_POST["email"]);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "* Invalid email format";
    }
  }
  if (empty($_POST["uname"])) {
    $unameErr = "* Username is required";
  } else {
    $uname = test_input($_POST["uname"]);
    if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) {
      $unameErr = "* Only letters and numerals are allowed";
    }
  }
  if (empty($_POST["pwd1"])) {
    $pwd1Err = "* Password is required";
  } else {
    $pwd1 = test_input($_POST["pwd1"]);
  }
  if (empty($_POST["pwd2"])) {
    $pwd2Err = "* Password confirmation is required";
  } else {
    $pwd2 = test_input($_POST["pwd2"]);
    if($pwd1 != $pwd2) {
    	$pwd2Err = "* Passwords do not match";
  }
}

if ( empty($pwd2Err) && empty($pwd1Err) && empty($unameErr) && empty($emailErr) && empty($lnameErr) && empty($fnameErr) ){ // Good to go
    $to = $email; // this is your Email address
    $from = "verify@dfwit.co"; // this is the sender's Email address
    $subject = "Form submission";
    $message = $fname . ":\n\n" . "Thank you for subscribing to DFW Information Technologies database services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nhttp:www.dfwit.co/index.html\n\n\n\nTech Support: techsupport@dfwit.co\nSales: sales@dfwit.co";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
    header("Location: www.dfwit.co/index.html"); // I put this in but it won't redirect until the mail
                                                 // This is a personal problem. If your email server is slow, that's too bad lol.
}


}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

 


?>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
<input type="text" name="fname" placeholder="First Name" value="<?php if (isset($_POST['fname'])) { echo $fname; } ?>">
	<span class="error"> <?php echo $fnameErr;?></span><br><br>
<input type="text" name="lname" placeholder="Last Name" value="<?php if (isset($_POST['lname'])) { echo $lname; } ?>">
	<span class="error"> <?php echo $lnameErr;?></span><br><br>
<input type="text" name="email" placeholder="E-mail Address" value="<?php if (isset($_POST['email'])) { echo $email; } ?>">
	<span class="error"> <?php echo $emailErr;?></span><br><br>
<input type="text" name="uname" placeholder="Username" value="<?php if (isset($_POST['uname'])) { echo $uname; } ?>">
	<span class="error"> <?php echo $unameErr;?></span><br><br>
<input type="password" name="pwd1" placeholder="Password" value="<?php if (isset($_POST['pwd1'])) { echo $pwd1; } ?>">
	<span class="error"> <?php echo $pwd1Err;?></span><br><br>
<input type="password" name="pwd2" placeholder="Confirm Password" value="<?php if (isset($_POST['pwd2'])) { echo $pwd2; } ?>">
	<span class="error"> <?php echo $pwd2Err;?></span><br><br>
<input type="submit" value="Submit"></button>
</form>
</body>
</html>
The email 'lag' you receive is a personal issue. If your email server is slow, that's too bad lol.

 

Hope this helps.

 

Also, put this:

 

echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";
At the welcome.html page. They won't see that echo. Edited by Monkuar
Link to comment
Share on other sites

Yeah, if it wld show me the error (like it seems to do for you), then I'd fix it. I loaded your code and ran it. Still hangs waiting on localhost. But when I uploaded it, it ran like greased lightning. So I will ask you again: is the error suppose to show in the browser? Because I'm getting nothing.

Link to comment
Share on other sites

Thank you, Monkuar:

 

I appreciate your help. I'll study what you've been so kind to offer me. I'm new at PHP, but I learn fast. But I wonder why I can't see thrown errors? I know that if I have bad syntax in my php that my page won't even load...but I never see the errors. I just have to sift through it and find what I can find.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.