2016-11-24 11 views
0

私は登録/ログイン/あなたが私がシステムについて話していることを知っているので、パスワードを忘れた場合にユーザーの電子メールアドレスを確認する必要があります。これを行うために、私は彼らに電子メールで送信されるランダムなPINを割り当てます。その後、アカウントの有効化ページにそのPINを入力し、アカウントが有効になったことを知らせます。PHP mail()not sending(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(); 
?> 

、I「は、はい、私は私が準備された文とPDOを学習に取り組んでいる、私はSQLインジェクションに対して脆弱だことを知って、はい、私はmysql_ *は道時代遅れであることを知っています新しい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はPOSTを取得することができないとの問題ではありません。

ありがとうございます!

答えて

1

私は、最初の2つのことを行うことをお勧めします:あなたが得たかどうかを確認

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

2.そして、あなたは、電子メールに続いて

$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>'; 
    } 

を送信している行を変更: 1.エラーログを有効にしますエラーがなければエラーを返します。この回答に従ってください:PHP mail form doesn't complete sending e-mail