Hi, would anyone be able to help me with my question. I am trying to enable users to register to my site, and then login after they’ve verified their email address. When they register, their details get inserted in a database and once that happens, the email is supposed to be sent to their email. I find that their details are being inserted into the table, but the email is not sending. I don’t know what I’m doing wrong and am at my wits end trying to figure it out. Here is my code:
By the way, sorry if I’m re-posting this message. I tried before and it didn’t seem to work so I’m posting it again.
[php]
$insert = “INSERT INTO useraccounts (confirm_code, email, username, passhash, firstname, lastname,
gender, phone, address, userlevel, confirmed) VALUES (’$confirm_code’, ‘$email’, ‘$_POST[username]’,
‘$passhash’, ‘$_POST[firstname]’, ‘$_POST[lastname]’, ‘$_POST[gender]’, ‘$_POST[phone]’,
‘$_POST[address]’, ‘user’, ‘false’)”;
$add_member = $conn->query($insert); // executes query $insert (adds user to table)
//send confirmation email if user is added to useraccounts
if($add_member) {
//send email to
$to = $email;
//email subject
$subject = 'Registration Confirmation';
//email message
$message = 'my message goes here';
$headers = 'From myname';
//send email
$sentmail = mail($to,$subject,$message,$headers);
//if email is sent
if($sentmail){
echo "Your Confirmation link has been sent to your email address.";
} else {
echo "Cannot send Confirmation link to your email address."; // this statement is the output
}
} else {
echo “Cannot send Confirmation link to your email address.”;
}
[/php]
Any help would be greatly appreciated