0

次のスクリプトは、すべての条件が満たされた場合に電子メールを送信し、「成功」を返すはずでした。ここでの問題は、「成功」を返しているのにメールが送信されていないことです。私は問題を把握するために最善を尽くしましたが、私は PHP を初めて使用するため、把握できません。だから私は可能な助けを探しています。どんな助けでも大歓迎です。前もって感謝します

$sql = "SELECT id, username FROM user WHERE email='$e' AND activated='1' LIMIT 1";
    $query = mysqli_query($db_conx, $sql);
    $numrows = mysqli_num_rows($query);
    if($numrows > 0){
        while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
            $id = $row["id"];
            $u = $row["username"];

        $emailcut = substr($e, 0, 4);
        $randNum = rand(10000,99999);
        $tempPass = "$emailcut$randNum";
        $hashTempPass = md5($tempPass);
        $sql = "UPDATE useroptions SET temp_pass='$hashTempPass' WHERE username='$u' LIMIT 1";
        $query = mysqli_query($db_conx, $sql);
        $to = "$e";
        $from = "auto_responder@geniusfree.net";
        $headers ="From: $from\n";
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1 \n";
        $subject ="GeniusFree Password Reset";
        $msg = '<h2>Hello '.$u.'</h2><p>This is an automated message from GeniusFree. If you did not recently initiate the Forgot Password process, please disregard this email.</p><p>You indicated that you forgot your login password. We can generate a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p><br /><p><a href="http://www.geniusfree.net/passwordreset.php?u='.$u.'&p='.$hashTempPass.'">Click here now to apply the temporary password shown below to your account</a></p><p>If you do not click the link in this email, no changes will be made to your account. In order to set your login password to the temporary password you must click the link above.</p>';
        if(mail($to,$subject,$msg,$headers)) {
            echo "success";
            exit();
        } else {
            echo "email_send_failed";
            exit();
        }}
4

3 に答える 3

1

MX エントリの設定を確認してください。最高の優先度は 0 です。ホストでメール サーバーを使用している場合。最初のエントリは、この優先度番号 0 ---> mail.yoursite.com のようなものにする必要があります。

これをデバッグする別の方法は、電子メール トレース ルートを使用することです。cpanelでできます。

お役に立てれば。

于 2013-04-17T06:40:47.507 に答える
0

最初に、サーバーから電子メールを送信するように php を構成する必要があります。ローカル ホスト マシンでコードを実行している場合は、電子メールを送信するように php.ini ファイルを構成する必要があります。コードが Web ホスティング サーバーで実行されている場合は、そのサーバーに連絡してください。 issue 、構成の詳細については、php で xampp を使用してメールを送信するを参照してください。

wamp のような別のローカル サーバーを使用している場合は、sendmail ユーティリティをサーバーに個別に (ダウンロード) インストールする必要があります。

これがうまくいくことを願っています

于 2013-04-17T06:57:09.117 に答える
-1

ローカルホストで実行しますか?その場合は、そこで動作しない可能性があります。Web ホストでテストして、結果をお知らせください。

于 2013-04-17T05:14:25.423 に答える