What I am trying to do is once a user signs up, he will get an email containing the password to their account (basically an email validation).
Problem is that it does add the query to the database, but the email does not get sent at all. No errors displays.
here is what I have:
function makePassword() {
$salt = str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 8) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$randomPass = makePassword();
$encrypted = md5($randomPass);
BTW, I added capital letters to be included in the password.
Then I have the function of the email itself:
function sendWelcomeEmail($sendEmail){
$MessageString = "Dear ".$_POST["contact_first"]." ".$_POST["contact_last"].",\r\n\r\n";
$MessageString .= "Thank you for registering at FindAgoodHost.com.\r\n";
$MessageString .= "Your account has now been activated and can be accessed immediately to update your profile, add plans, signup for our various services and much much more!r\n\r\n";
$MessageString .= "Your login details are as follow:"."\r\n\r\n";
$MessageString .= "Login at:"."\r\n"."http://www.findagoodhost.com/host/index.php\r\n\r\n";
$MessageString .= "Username:"."\r\n".$_POST["contact_email"]."\r\n\r\n";
$MessageString .= "Password:"."\r\n".$randomPass."\r\n\r\n\r\n";
$MessageString .= "Do not forget to register on our forums at [url]http://www.findagoodhost.com/forum[/url], ";
mail($email, "FAGH Account Details", $MessageString, "From: FindAGoodHost");
}
Then I check for errors (such as the right email format is entered,...), but I won't include it here since it is irrelevent.
So now I have this:
if ($total == 1)
{
header("Location: dp.php");
exit;
}
else
{
sendWelcomeEmail();
mysql_query($query,$conn) or die("SQL error: ".mysql_error());
mysql_close($conn);
header("Location: ty.php");
exit;
}
That's just saying that if there are errors, display them. Otherwise send the password by email, and add all the fields to the db.
Now the query gets added to the db fine (I can see the row in phpmyadmin), but it does not send the email.
What am I doing wrong?
Thanks