誰かが私の質問を手伝ってくれるでしょうか。ユーザーが自分のサイトに登録し、電子メール アドレスを確認した後にログインできるようにしようとしています。彼らが登録すると、その詳細がデータベースに挿入され、それが起こると、電子メールは彼らの電子メールに送信されることになっています。詳細がテーブルに挿入されていることがわかりましたが、電子メールは送信されていません。私は何が間違っているのかわからず、それを理解しようとして機知に富んでおり、エラーメッセージも表示されません。また、私はPHPを長い間使用していません。データベースも接続しています。これが私のコードです:
$email = $_POST['email'];
$emailcheck = "SELECT email FROM useraccounts WHERE email = '$email'";
$result = $conn->query($emailcheck); // executes query $emailcheck
//if the email exists it gives an error
if ($result->num_rows != 0) {
echo "Sorry, the email $email is already in use.";
}
// check to see if both passwords entered match
if ($_POST['password'] != $_POST['confirmpassword']) {
echo "Your passwords did not match. Please try again.";
}
// to encrypt the password
$passhash = sha1($_POST['password']);
// to make confirm_code
$confirm_code = sha1($email);
if ($result->num_rows == 0 && $_POST['password'] == $_POST['confirmpassword']) {
$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 = $_POST['email'] is present at top
//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
} // end if email is sent
} else {
echo "Cannot send Confirmation link to your email address.";
} // end if member is added
}
どんな助けでも大歓迎です:)