2012-10-11 107 views
-4

我有這種形式註冊用戶併發送電子郵件來驗證電子郵件是否正確,並存在用戶註冊確定但「驗證電子郵件」未發送給用戶電子郵件註冊表單不發送電子郵件給用戶

這裏是PHP代碼

<?php 

if (isset($_POST['submited'])) { 
    $msg = ""; 

    $RFname = clean_text($_POST['RFname']); 
    $RLname = clean_text($_POST['RLname']); 
    $USERname = clean_text($_POST['UserName']); 
    $USERpassword = $_POST['UserPass']; 
    $USERpassword2 = $_POST['UserPassConfirm']; 
    $USERemail = $_POST['UserEmail']; 
    $USERwebsite = $_POST['WebSite']; 
    $hash = clean_text(md5(rand(0, 1000))); 
    $checkEmail = $db->query("select * from loginaccess where Email ='" . $USERemail . "'"); 
    $checkUID = $db->query("select * from loginaccess where Uname ='" . $USERname . "'"); 


    if ($USERpassword !== $USERpassword2) { 
     $msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>Passwords did not match</span>"; 
    } elseif ($checkEmail->num_rows == 1) { 
     $msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>This email already taken</span>"; 
    } elseif ($checkUID->num_rows == 1) { 
     $msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>This User name already taken</span>"; 
    } elseif (empty($_SESSION['6_letters_code']) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { 
     $msg = "<span class='errorMessges'>Human code verification invalid</span>"; 
    } else { 
     $putData = "insert into loginaccess (id, FUname, LUname, Uname, Pword, Email, Website, hash) value ('', '$RFname', '$RLname', '$USERname', '$USERpassword', '$USERemail', '$USERwebsite', '$hash')"; 
     $inputResult = $db->query($putData) or die ('$db->error'); 
     if ($inputResult) { 
      $msg = "<span class='successMessgaes'>You have been successfully registered</span>"; 

      // Send email to our user 
      $to = '$USERemail'; 
      $subject = 'Signup | Verification'; 
      $message = " 

     Welcome to Learning and share. 

    Before you can use your new account you must activate it - this ensures the e-mail address you used is valid and belongs to you. To activate your account, click the link below or copy and paste the whole thing into your browser's location bar: 

    -------------------------------------------------------------------------------------------------------- 
    http://www.yourwebsite.com/verify.php?email='.$USERemail.'&hash='.$hash.' 
    -------------------------------------------------------------------------------------------------------- 

    Once you've successfully activated your account, you can throw away this e-mail. 

    Thanks! 

    The Learning and share staff 


    "; 
      $headers = 'From:[email protected]' . "\r\n"; 
      mail($to, $subject, $message, $headers); 
     } else { 
      $msg = "<span class='errorMessges'>There was an error please try again later</span>"; 
     } 
    } 
} 
?> 

,這是HTML代碼

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> 

    <table width="762" border="0" cellspacing="5" cellpadding="5"> 
     <tr> 
      <td colspan="2" class="socialAndPeopleByName">Personal information</td> 
      <td colspan="2"><span class="socialAndPeopleByName">Account information</span></td> 
     </tr> 
     <tr> 
      <td width="91" class="registrationInfo"><span class="red">*</span> First name</td> 
      <td width="203"><label for="textfield"></label> 
       <span id="sprytextfield1"> 
       <input name="RFname" type="text" class="registrationFeild" id="textfield"/> 
       <span class="textfieldRequiredMsg"><br> 
       First name is required.</span></span></td> 
      <td width="148"><span class="red">*</span><span class="registrationInfo"> User name</span></td> 
      <td width="255"><span id="sprytextfield5"> 
       <input name="UserName" type="text" class="registrationFeild" id="textfield5"/> 
       <span class="textfieldRequiredMsg"><br> 
       User name is required.</span></span></td> 
     </tr> 
     <tr> 
      <td class="registrationInfo"><span class="red">*</span> Last name</td> 
      <td><span id="sprytextfield2"> 
       <input name="RLname" type="text" class="registrationFeild" id="textfield2"/> 
       <span class="textfieldRequiredMsg"><br> 
       Last name is required.</span></span></td> 
      <td><span class="red">*</span><span class="registrationInfo"> Password</span></td> 
      <td><span id="sprypassword1"> 
      <input name="UserPass" type="password" class="registrationFeild" id="textfield7"/> 
      <span class="passwordRequiredMsg"><br> 
      Password is required.</span><span class="passwordMaxCharsMsg"><br> 
      Password can't be more then 20 letter</span><span class="passwordMinCharsMsg"><br> 
      Password can't be less then 6 letter</span></span></td> 
     </tr> 
     <tr> 
      <td class="registrationInfo"><span class="red">*</span> Valid email</td> 
      <td><span id="sprytextfield3"> 
      <input name="UserEmail" type="text" class="registrationFeild" id="textfield3"/> 
      <br> 
      <span class="textfieldRequiredMsg">Valid email is required.</span><span class="textfieldInvalidFormatMsg">Invalid email format.</span></span> 
      </td> 
      <td><span class="red">*</span><span class="registrationInfo"> Confirm Password</span></td> 
      <td><span id="sprypassword2"> 
       <input name="UserPassConfirm" type="password" class="registrationFeild" id="textfield8"/> 
       <span class="passwordRequiredMsg"><br> 
       Please confirm your password</span></span></td> 
     </tr> 
     <tr> 
      <td class="registrationInfo">Web site</td> 
      <td><span id="sprytextfield4"> 
       <input name="WebSite" type="text" class="registrationFeild" id="textfield4"/> 
       <br> 
       <span class="textfieldInvalidFormatMsg">Invalid format</span></span></td> 
      <td><span class="registrationInfo"><span class="red">*</span> Prove you are human</span></td> 
      <td><img src="includes/captcha.php?rand=<?php echo rand(); ?>" align="absmiddle" id='captchaimg'/> <a 
        href="javascript: refreshCaptcha();"><img src="images/refreshIcon.jpg" alt="Refresh" width="18" 
                   height="25" border="0" align="absmiddle"/></a> <input 
        name="6_letters_code" type="text" class="registrationFeildSmall" id="6_letters_code"/></td> 
     </tr> 
     <tr> 
      <td colspan="3"><?php if (!empty($msg)) { 
        echo $msg; 
       } ?></td> 
      <td><input name="submited" type="submit" class="signUpItem" id="submited" value=""/></td> 
     </tr> 
    </table> 
</form> 

用戶之後會發生什麼報名方式:

  1. 新用戶成功插入數據庫。
  2. 用戶收到消息「您已成功註冊」。

問題:這裏是用戶永遠不會收到他的驗證郵件的問題。

+0

我能理解爲什麼你評價我評價之前評論你(...) –

+1

*「它不起作用」*和*「請在這方面需要幫助」* [不解釋問題] (http://stuck.include-once.org/#help3)就夠了。您需要詳細說明您的輸入,預期結果和實際結果,或詳細說明錯誤消息。否則,這不被視爲一個問題。 – hakre

+0

看到我的新編輯@hakre –

回答

0

變化:

$to='$USERemail'; 

要:

$to = $USERemail; 

PHP不允許在單引號字符串變量插值。

+0

謝謝@tehlulz是不是一個非常適合的問題類型是這是它現在工作正常的問題 –

1

你寫過郵件發送確認郵件時發生問題。你需要檢查它是否基本正常工作,如果沒有,請爲你自己提供一些調試信息。

mail function有返回值:

返回TRUE如果郵件被成功接受交付,否則FALSE

重要的是要注意,僅僅因爲郵件被接受交付,並不意味着郵件實際上會到達預定的目的地。

利用返回值編寫更穩定的代碼。否則,你會一直坐在黑暗中。

一個粗略的例子:

... 

$headers = 'From:[email protected]' . "\r\n"; 
$send = mail($to, $subject, $message, $headers); 
if (!$send) { 
    echo "Failed to send Email:\n"; 
    var_dump($to, $subject, $message, $headers); 
    die(); 
} 

然後找到實際的問題。如果報告已發送電子郵件,但您沒有看到它已發送,請檢查您的發送郵件錯誤日誌。

+0

感謝您的回答我已經從中瞭解了很多。 –

相關問題