PHP mail()不发送(Hostinger) [英] PHP mail() not sending (Hostinger)

查看:113
本文介绍了PHP mail()不发送(Hostinger)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在注册/登录/你知道我在说什么系统,我需要验证用户的电子邮件地址,以防他们忘记密码。为此,我给他们分配一个随机的PIN码,通过电子邮件发送给他们。然后,他们在帐户激活页面中输入该PIN码,并且他们的帐户变为活动状态。

So I'm making a registration/login/you know what I'm talking about system, and I need to verify the user's email addresses in case they forget their password. To do that, I assign them a random PIN which gets sent to them by email. Then, they enter that PIN in the account activation page and yay their account becomes active.

现在,我的问题是电子邮件不发送。
我在Hostinger上使用PHP 5.5,我的MX记录没有设置,但是从我已经读过的问题中,这不是导致问题的原因。这是代码:

Now, my problem is the e-mail just isn't sending. I'm using PHP 5.5 on Hostinger, my MX records aren't set up but from the questions that I've read about this, it's not what's causing the problem. Here is the code:

<?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='admin@komodokrew.ml';
            $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_ *是过时的,我正在学习新的PDO的东西,好吗?但是即使他们注入了SQL,它也会在注册之后重定向它们,密码和用户名可以用不同的盐分散在几十万次,所以我现在不太担心。

Also, yes I KNOW that I'm vulnerable to SQL injections, I'm working on learning prepared statements and PDO, and yes I KNOW that mysql_* is way outdated, I'm working on learning the new PDO stuff, okay? But even if they SQL-injected me, it redirects them after they register anyways, and passwords and usernames are hashed with a varying salt several hundreds of thousands of times, so I'm not too worried at the moment.

这是在php_mail.log中发送的典型日志:

This is the typical log that's sent in php_mail.log:

[23-Nov-2016 22:20:28 UTC] mail() on [/home/u964873932/public_html/register/register.php:40]: To: <myEmailAddressThatImNotGonnaTellYou> -- Headers: From:admin@komodokrew.ml

这不是一个问题,PHP无法得到POST,因为用户的电子邮件地址成功登录到数据库中。

It's not a problem with PHP not being able to get the POST, because the email address of the user gets entered in the database successfully.

谢谢!

推荐答案

我建议先做2件事:
1.启用错误日志:

I would recommend to do 2 things first: 1. Enable error log:

error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

2。并更改发送电子邮件的行

2. And change the line where you are sending email

$status = mail($email,$subject,$message,$headers);

 if($status)
   { 
    echo '<p>Your mail has been sent!</p>';
    } else { 
     echo '<p>Something went wrong, Please try again!</p>'; 
  }

然后看看是否有任何错误,如果没有错误,请按照以下答案:一个href =https://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail> PHP邮件表单不完成发送电子邮件

Then see if you got any error if no error then Follow this answer: PHP mail form doesn't complete sending e-mail

这篇关于PHP mail()不发送(Hostinger)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆