Hello again I have a problem. I was following tutorials and I came up with some code to register for the game witch I have no problem doing, but it is sending email conformation. Here is my code. The problem is I dont get the email and when I submit the form it goes to the "Thank You" page. Why is that??

<?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 email
                $query2="SELECT * FROM users WHERE email = '$_POST[email]'";
                $result2=mysql_query($query2);
                $num2 = mysql_num_rows($result2);

                    if($num2==0){

                            //if emails and passwords match up
                            if(($_POST['pass']==$_POST['pass2'])&&($_POST['email']==$_POST['email2'])){



                                // Random confirmation code
                                $confirm_code=md5(uniqid(rand()));

                                // values sent from form
                                $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', password='$pass'";
                                $result=mysql_query($sql);

                                    if($result){

                                        $message="Your Comfirmation link \r\n";
                                        $message.="Click on this link to activate your account \r\n";
                                        $message.="http://kaphp.f-snet.com/confirmation.php?passkey=$confirm_code";

                                        $sentmail=mail("$email",'Registration Conformation',"$message");
                                        header("Location:thankyou.html");
                                    }
                                    else {
                                    echo "Not found your email in our database";
                                    }

                                    // if your email succesfully sent
                                    if($sentmail){
                                    echo "Your Confirmation link Has Been Sent To Your Email Address.";
                                    }
                                    else {
                                    echo "Cannot send Confirmation link to your e-mail address";
                                    }

                            }else{
                            header("Location:badmatch.html");
                            }
            
                }else{
                header("Location:emailinuse.html");
                }

            
        }else{
        header("Location:nameinuse.html");
        }    

}else{
header("Location:invalidname.html");
}        
?>

Thank you.

Recommended Answers

All 8 Replies

I believe

// if your email succesfully 
if($sentmail){
  echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
  echo "Cannot send Confirmation link to your e-mail address";
}

should come after

$sentmail=mail("$email",'Registration Conformation',"$message");

.

At the moment, you are using the mail() and then re-directing without checking if the send was successful.

Ok thank you it says "Your Confirmation link Has Been Sent To Your Email Address." About how long until it gets to my inbox? Thank you again.

Probably not too long. You would have to ask your host but it should take somewhere between 2-5 minutes. Also you should change $testname=$_POST[username]; so that it looks like this: $testname=$_POST["username"]; .

Ok thank you for the info. That must be the problem because I woke up this morning and it wasnt in my mailbox. I will try that thank you.

Well...I tried. It still dosnt send to email. It shows up in the temp database and it says email successful but it dosnt show up in mailbox. Should I skip it and just but a secerety code? that has letters and says type in the letters to gain access to the website? will that work? Thank you everyone.

It will work, but there should be no problems with the mailing. Who are you using to host your website?

freespace.net
I want a good cpanel one. Do you have any others?? Thank you again.

Yes well that seems to be pretty good. Here are some others that fix your needs (I'm assuming...):
http://www.free-webhosts.com/search-webhosts.php?ADV=00100000001000000000000000100000000010000000

But Freespace seems to be OK (Get ready because it seems like that they reject lots of sites, even though on their site they say "Instant Activation"). Also, I had a heck of a time trying to do a search. Their CAPTCHA's are very hard to read and they make you type "www.free-space.net" in a box to make sure you aren't spamming (Don't understand this, let's remember this is only the forum search). I'm not sure though if they allow the PHP mail command (They should though since you have 5 mail accounts).

To check whether the mail function works make a PHP file and call it mailcheck.php and add this code:

<?php
if(function_exists('mail')) echo "Mail function is enabled! Yay! :D";
else echo "Mail is not enabled. :(";
?>

Open the page and well, I think the results are quite clear. Be sure to delete the file afterwords (Hackers these days can exploit Hello World scripts!! :O)

If you need any help with further picking a host or checking/designing your site, feel free to PM me. I check DaniWeb regularly.

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.