Not receiving activation email

Thanks to Guido, I troubleshot my login.php down to a stupid mistake on my part, now I’m having problems with my register.php, the form works, info gets written to the database, folder gets created on the server, but I am not getting the activation email, now being new to php, I’m not sure if it’s a server thing, or a code thing, so here is the code for my register.php:


<?php
$errorMsg = ""; 
if (isset($_POST['username'])){ 
	include_once "connect_to_mysql.php";
	$username = ereg_replace("[^A-Za-z0-9]", "", $_POST['username']);
	$country = ereg_replace("[^A-Z a-z0-9]", "", $_POST['country']);
	$state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']);
	$city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']);
	$email = stripslashes($_POST['email']);
	$email = strip_tags($email);
	$email = mysql_real_escape_string($email);
	$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']);
	if((!$username) || (!$country) || (!$state) || (!$city) || (!$email) || (!$password)){
		
		$errorMsg = "You did not submit the following required information!<br /><br />";
		if(!$username){
			$errorMsg .= "--- User Name";
		} else if(!$country){
			$errorMsg .= "--- Country"; 
		} else if(!$state){ 
		    $errorMsg .= "--- State"; 
	   } else if(!$city){ 
	       $errorMsg .= "--- City";  
	   } else if(!$email){ 
	       $errorMsg .= "--- Email Address"; 
	   } else if(!$password){ 
	       $errorMsg .= "--- Password"; 
	   }
	} else {
	$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
	$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
	$username_check = mysql_num_rows($sql_username_check);
	$email_check = mysql_num_rows($sql_email_check); 
	if ($username_check > 0){ 
		$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
	} else if ($email_check > 0){ 
		$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
	} else {
       $hashedPass = md5($password); 
		$sql = mysql_query("INSERT INTO members (username, country, state, city, email, password, signupdate) 
		VALUES('$username','$country','$state','$city','$email','$hashedPass', now())") or die (mysql_error());
		$id = mysql_insert_id();
		mkdir("memberFiles/$id", 0755);
		$to = "$email";
		$from = "admin@twinrecords.net";
		$subject = "Complete your registration";
		$message = '<html>
		<body bgcolor="#FFFFFF">
		Hi ' . $username . ',
		<br /><br />
		You must complete this step to activate your account with us.
		<br /><br />
		Please click here to activate now >>
		<a href="http://www.twinrecords.net/activation.php?id=' . $id . '">
		ACTIVATE NOW</a>
		<br /><br />
		Your Login Data is as follows: 
		<br /><br />
		E-mail Address: ' . $email . ' <br />
		Password: ' . $password . ' 
		<br /><br /> 
		Thanks! 
		</body>
		</html>';
		
		$headers = "From: $from\\r\
";
		$headers .= "Content-type: text/html\\r\
";
		$to = "$to";
		mail($to, $subject, $message, $headers);
		print "<br /><br /><br /><h4>OK $username, one last step to verify your email identity:</h4><br />
		We just sent an Activation link to: $email<br /><br />
		<strong><font color=\\"#990000\\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
		Link inside the message. After email activation you can log in.";
		exit();
	}
  }
}
?>

mail($to, $subject, $message, $headers);

    if(!mail($to, $subject, $message, $headers)) {
       echo "Mail Failure";
    }

ok, I put that in and I didn’t get any mail errors or delivery failures, still everything went through fine, I just didn’t get the email.

maybe some of you guys can try it and see if you get the email

Digital Music Distribution

I’ve tried your link and i got no email either.

Can you tell us what operating system you’re using? (EG windows, linux, home PC or proper hosting), is sendmail installed?

I’ll help you nail this if you can give me details i need step by step.

Ok Thank you

I’m building it on my mac, mac os 10.6.7, using Dreamweaver cs5 then testing it on proper hosting

Debian Linux

Mysql-5.0.83
PHP-5.2.12
path to sendmail-/usr/bin/sendmail

what else can I provide for you?

Scratch that, i’ve just had two turn up showing they were sent at 19:12pm - it’s 20:42 so must of been a mail delay in yahoo :frowning:

I’m not sure what to think now to be honest. I got two emails with the following link:

http://www.twinrecords.net/activation.php?id=6

Clicking that gave me a 404 error though but the emails did turn up (over an hour after they were sent - this isn’t the first time i’ve had problems with yahell either with mail delays).

Have you tried whipping up a quick dirty script to send to send a test email to yourself?

weird, because I still have not received any of the activation emails, I should have about 5, the info is getting written to the DB, and the 404 error shows because I have not built the activation page yet.

being new to php, I’m trying to learn it properly, I have not figured out how to write a script to send email to myself.

Try dumbing it down first.

New page:


        if(!mail("your@email.here", "This is a test.", "It works.")) {
           echo "It didnt work.";
        }

Visit the page, wait a couple minutes, check your email. (Also check your junk folders, cause this may get flagged as junk).

If you get the email, then we’ve got a problem with content.
If you dont, we’ve got a problem with the system.

I wrote a quick one, got the message that the mail was sent, but I am still not receiving it, so is this something that I need to talk to my hosting provider about?

ok, I tried this one as well, still didn’t work

I’ve tried 3 different email addresses, nothing…so I guess it’s a system problem

It looks that way but there could be a mail queue on the server which is sending stuff out as-and-when.

Get in touch with the host and see what they say.

I will do that, I’ll post what I gather

thanks guys

ok, as it turns out, the one server I was test sending to, had a spam assassin set to the highest setting, autodeleting everything it thought was spam, so I changed that, it’s working now, the other server, it just started working all of a sudden, I didn’t change anything, just started working.

I am having one problem though, when I test register, I get 2 activation emails, I’m afraid I don’t know php enough to figure out why, if someone could direct me to the possible reason in the code at the top, I can try to figure it out from there.

I can’t see anything obvious…

I can help you debug it if you can download TeamViewer and PM me your connection details but you need to do it fast as it’s 23:12 here and I’m aiming for bed by 23:45!

Ok, it’s 23:31 now so there’s not enough time left for me to assist you today.

Maybe we can try again tomorrow.

sorry dude, I was working on some other pages, dealing with kids…etc…I appreciate your help, i will download teamviewer