2016-11-24 105 views
0

因此,我正在進行註冊/登錄/您知道我在說什麼系統,並且我需要驗證用戶的電子郵件地址以防萬一他們忘記了密碼。爲此,我爲他們分配一個隨機的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不能夠得到這個職位的問題,因爲用戶的電子郵件地址數據庫被成功輸入。

謝謝!

回答

1

我會建議先做兩件事情: 1.啓用錯誤日誌:

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

然後行看,如果你有任何錯誤,如果沒有錯誤然後按照這個答案:PHP mail form doesn't complete sending e-mail