3

メールを送信する次のコードがあります。

これは、本番環境に十分な安全性と安全性を備えていますか? つまり、ボット、それを使用してスパムを送信するカール スクリプト、電子メール インジェクションなどを停止しますか?

<?php

    require_once('recaptchalib.php');
    $privatekey = "private keys goes here";
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);

    if (!$resp->is_valid) {

        // What happens when the CAPTCHA was entered incorrectly
        die ("The reCAPTCHA wasn't entered correctly. Go back and try it again. " .
             "(reCAPTCHA said: " . $resp->error . ")");

    } else {

        require 'class.phpmailer.php';

        //Create a new PHPMailer instance
        $mail = new PHPMailer();

        //Set who the message is to be sent from
        $mail->SetFrom('oshirowanen@localhost.com');

        //Set who the message is to be sent to
        $mail->AddAddress($_POST['email']);

        //Set the subject line
        $mail->Subject = 'subject goes here';

        //Replace the plain text body with one created manually
        $mail->Body = $_POST['message'];

        //Send the message, check for errors
        if(!$mail->Send()) {

            die ("Mailer Error: " . $mail->ErrorInfo);

        } else {

            echo "Message sent!";

        }

    }

?>

基本的に、私が求めているのは、上記のコードは十分に安全で、十分に安全で、本番環境に十分適しているかということです.

4

6 に答える 6

4

さらに2つのオプションをお勧めします:

I.) 追加の入力 txt フィールドを送信フォームに配置し、css スタイル、fe を使用してユーザーに対して非表示 (非表示) にすることができます。

<input type="text" id="commentary" style="display: none;">
<!-- OR -->
<input type="text" id="commentary" style="opacity: 0;">
<!-- OR -->
<input type="text" id="commentary" style="position: absolute; left: -100px; top: -100px;">

<!-- 
The trick is, user won't see these forms and WILL NOT FILL THEM. 
And bot will, so you can easily filter them without even using CAPTCHA. 
-->

II.) ユーザーのリストを作成し (IP、名前、Cookie ID、ユーザー ID、サイトで承認されたときに電子メールを送信した場合など)、同様の電子メールを連続して送信しないようにすることができます。 (短い期間で)。スパム ボットをフィルタリングするルールを実装することもできます。ユーザーが頻繁に送信しようとすると、ブロックされる可能性があります。もう 1 つのオプションは、許可されたユーザーの「ホワイト リスト」を作成することです。許可されたユーザーは、より自由に、より広い制限でメールを送信できます。

于 2013-08-29T10:01:40.270 に答える
4

以前にphpメーラーを使用したことはありませんが、安全性、エスケープなどを処理する必要があります。
しかし、あなたのコードはよさそうです:

  • 送信前にエンコーディング チェックを追加してスクリプトを改善します。たとえば、次のようにします。

    iconv("UTF-8", "UTF-8//IGNORE", $subject_or_message_or_any_string);
    
  • また、メールの送信に失敗した場合は情報を表示しません。代わりに、次のようなものを使用します。

    if (!$mail->Send())
    {
        LogErrorMessage("Mailer Error: %s", $mail->ErrorInfo);
        die ("Sorry, mail could not be sent");
    }
    
  • 次に、メール フォームを送信したユーザーの IP アドレスを送信またはログに記録します。ユーザーがスパムを好む場合は、簡単にブロックできます。

于 2013-08-27T20:15:29.757 に答える
0

それでも安全ではないと感じる場合は、セキュリティを追加することができます。
フォームに次を追加します。

<input name="url" style="display:none">

次に、この変更コードの後:

else if($_REQUEST['url']){

    require 'class.phpmailer.php';

    //Create a new PHPMailer instance
    $mail = new PHPMailer();

    //Set who the message is to be sent from
    $mail->SetFrom('oshirowanen@localhost.com');

    //Set who the message is to be sent to
    $mail->AddAddress($_POST['email']);

    //Set the subject line
    $mail->Subject = 'subject goes here';

    //Replace the plain text body with one created manually
    $mail->Body = $_POST['message'];

    //Send the message, check for errors
    if(!$mail->Send()) {

        die ("Mailer Error: " . $mail->ErrorInfo);

    } else {

        echo "Message sent!";

    }
于 2013-09-02T10:26:25.353 に答える