因此,我正在进行注册/登录/您知道我在说什么系统,并且我需要验证用户的电子邮件地址以防万一他们忘记了密码。为此,我为他们分配一个随机的PIN码,通过电子邮件发送给他们。然后,他们在账户激活页面输入该PIN码,并且他们的账户变为激活状态。PHP邮件()不发送(Hostinger)
现在,我的问题是电子邮件只是不发送。 我在Hostinger上使用PHP 5.5,我的MX记录没有设置,但是从我读到的有关这个问题的问题来看,这不是导致问题的原因。下面是代码:
<?php
// connect to database, I'll omit the details because no one cares
$pin=rand(1000,9999);
$email=$_POST['email'];
$rawUser=$_POST['user'];
$user=// hash username but I'm not gonna tell you how because safety reasons
$rawPassA=$_POST['pass1'];
$rawPassB=$_POST['pass2'];
if($rawPassA==$rawPassB){
// hash password, again I'm not gonna tell you how
} else{
echo "<script type='text/javascript'>
window.location.href = 'http://komodokrew.ml/error/login/pass_no_match';
</script>";
};
$first=$_POST['first'];
$checkForUserQuery='SELECT count(*) FROM tableNameThatImNotGonnaTellYouBecauseSqlInjection WHERE user = \'' . $user . '\';';
$checkForUser=mysql_query($checkForUserQuery);
$checkForUserA=mysql_fetch_row($checkForUser);
$checkForUserF=$checkForUserA[0];
if($checkForUserF==0){
$query='INSERT INTO tableNameThatImNotGonnaTellYouBecauseSqlInjection (`user`,`first_name`,`pin`,`password`,`email`,`active`) VALUES (\'' . $user . '\',\'' . $first . '\',' . $pin . ',\'' . $pass . '\',\'' . $email . '\',1);';
mysql_query($query);
$subject='KomoDoKrew - account activation';
$message='You have recently registered an account on KomoDoKrew, under the username ' . $rawUser . '. Please activate your account by visiting komodokrew.ml/activate and entering the following PIN code, your username, and your password. PIN code: ' . $pin . '. Thank you for registering an account with KomoDoKrew! Make sure to join the community at komodokrew.ml/forum.';
$from='[email protected]';
$headers='From:' . $from;
mail($email,$subject,$message,$headers);
echo "<script type='text/javascript'>
window.location.href = 'http://komodokrew.ml/success/login/register';
</script>";
} else{
echo "<script type='text/javascript'>
window.location.href = 'http://komodokrew.ml/error/login/user_exists';
</script>";
};
mysql_close();
?>
而且,是的,我知道我容易受到SQL注入,我正在学习准备的语句和PDO,是的,我知道mysql_ *的方式已经过时了,我m正在学习新的PDO东西,好吗?但即使他们注入了SQL,它仍会在注册后重定向它们,而且密码和用户名会被数十万次变换为盐,所以我现在并不担心。
这是在php_mail.log发送的典型日志:
[23-Nov-2016 22:20:28 UTC] mail() on [/home/u964873932/public_html/register/register.php:40]: To: <myEmailAddressThatImNotGonnaTellYou> -- Headers: From:[email protected]
这不是用PHP不能够得到这个职位的问题,因为用户的电子邮件地址数据库被成功输入。
谢谢!