No email received after sign up ?

Hi all and a happy new year, I have a problem in that I have followed a tutorial to make a log in and register page for a members only site I am doing, I have got the page up but when I register I don’t receive an email to confirm my registration, it shows in SQL in myphpadmin I have tried different email addresses but to no avail please help folks…thanks Arnie.

Post the relevant code
Post any error messages

Where are you running this code? Locally or at a web host?

Hi Jim, it is being hosted on a server , I get no error message, i says thank you an email has been sent for confirmation but it never arrives ?

<? include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information!
'; if(!$first_name){ echo "First Name is a required field. Please enter it below.
"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.
"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.
"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.
"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors:
"; if($email_check > 0){ echo "Your email address has already been used by another member in our database. Please submit a different Email address!
"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!
"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ /* Random Password generator. http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); // Enter info into the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at MyWebsite!"; $message = "Dear $first_name $last_name, Thank you for registering at our website, http://www.mydomain.com! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click here: http://thq.net63.net/member/activate.php?id=$userid&code=$db_password Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: MyDomain Webmaster\nX-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; } ?>

I would recommend changing from mail to phpmailer (https://github.com/PHPMailer/PHPMailer). The built in mail function only give you a boolean in return so you can check that to see if something went wrong, but not what went wrong. PHPMailer have much better error reporting and config options available.

Thanks for the reply, which file do I need to be looking in to see why the [email protected] hasn’t been sent, I am a complete beginner , everything seems to work except receiving the email ?, there can’t be much wrong as I don’t get any error messages, does SQL only store the user info or does it have anything to do with the email being sent ?

As said the built in mail function dont pffer any error handling. It only return a boolean saying if it was successful or not

Stop using out of date code, this has been deprecated for quite some time now. (like 10+ years!)

Also, don’t do this;
[php]<? // don’t do this!

<?php // do this instead.[/php] Trust me, very trivial but it will trip you up at some point. Hope that helps, Red ;)

Not really sure what that means, but I’ll take note [embed=425,349][/embed]

This the temporary page I am using … http://thq.net63.net/member/join_form.php , how frustrating it can be !

Look here, First paragraph covers everything.

Ok, so start again from scratch really then ?

No no no… well yes kind of…
Ok, let me explain.
The parts of your code that use mysql functions should be updated to use current code.
Here you have a choice, mysqli or PDO.
Personally i use mysqli - mainly because when it changed i found that the easiest to (re)learn.
There are many on this site who prefer PDO and they too will have their own reasons.

Ultimately, I believe it comes down to personal preference as there is not too much difference between them performance wise. PDO is compatible with more databases but if you only use mysql this negates this argument.

I say, try both and see which you prefer.
The rest of the code is ok.

Red :wink:

OK, thanks for your help, i’ll give it a go !! :slight_smile:

Another argument is that a lot of frameworks/libraries have decided on PDO, biggest ones may be Zend and Symfony that both use it… ^^

Sponsor our Newsletter | Privacy Policy | Terms of Service