I am getting this error while trying to make a register form:
Could not find your email in our database
Cannot send confirmation link to your email address
Why would it not be sending?
This is the PHP:
<?php
include('config.php');
//test to see if username is alphanumeric
$testname = $_POST['username'];
if (!eregi('([^A-Za-z0-9])',$testname)){
//test for duplicate names
$query = "SELECT * FROM users WHERE username='$_POST[username]'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num == 0){
//test for duplicate emails
$query2 = "SELECT * FROM users WHERE email='$_POST[email]'";
$result2 = mysql_query($query2);
$num2 = mysql_num_rows($result2);
if ($num == 0){
//test if emails and passwords match up
if(($_POST['pass']==$_POST['pass2'])&&($_POST['email']==$_POST['email2'])){
//generate random confirmation code
$confirm_code = md5(uniqid(rand()));
//get rid of all html from hackers
$name=strip_tags($_POST['username']);
$email=strip_tags($_POST['email']);
$pass=strip_tags($_POST['pass']);
//insert data into database
$sql="INSERT INTO temp SET code='$confirm_code',username='$name',email='$email',pass='$pass'";
$result3 = mysql_query($sql);
if ($result3){
$message = "Your Confirmation link \r\n";
$message .= "Click on this link to activate your account \r\n";
$message .= "localhost/PHPTUT/confirmation.php?passkey=$confirm_code";
$sentmail = mail($email,'Registration Confirmation',$message,'From: email@example.com');
header("Location:thankyou.html");
}else{
echo 'Could not find your email in our database';
}
//if your email successfully sent
if($sentmail){ // **LINE 47**-------------------
echo 'Your confirmation link has been sent to your email address.';
}else{
echo 'Cannot send confirmation link to your email address';
}
}else{
header("Location:badmatch.html");
}
}else{
header("Location:emailinuse.html");
}
}else{
header("Location:nameinuse.html");
}
}else{
header("Location:invalidname.html");
}
?>
This is the Form:
<form name="form1" method="POST" action="registernext.php">
<p>Username:</p>
<p><input type="text" name="username" size="25" maxlength="20" value=""></p>
<p>Password:</p>
<p><input type="password" name="pass" size="25" maxlength="20" value=""></p>
<p>Confirm Password:</p>
<p><input type="password" name="pass2" size="25" maxlength="20" value=""></p>
<p>Email:</p>
<p><input type="text" name="email" size="25" maxlength="65" value=""></p>
<p>Confirm Email:</p>
<p><input type="text" name="email2" size="25" maxlength="65" value=""></p>
<p><input type="submit" name="submit" value="Register"></p>
</form>