-3
    PHP

<?php
$field_name = $_POST['cf_name'];
$field_subject = $_POST['cf_subject'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'wermedia@hotmail.com';
$subject = 'Melding fra nettsiden: '.$field_subject;
$mail_noreply = 'noreply@wermedia.com';

$body_message = 'From: '.$field_name."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = "From: $field_name <$field_email> \r\n";
$headers .= "Reply-To: .$field_email.\r\n";
$headers .= "Return-Path: .$field_email.\r\n";
$headers .= "X-Mailer: Drupal \n";
$headers .= 'MIME-Version: 1.0' . "\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

$confirmationSubject='Confirmation message';
$displayForm=true;

if ($_POST){
$field_email=stripslashes($_POST['cf_email']);
$field_message=stripslashes($_POST['cf_message']);
// validate e-mail address
$valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$field_email);
$crack=eregi("(\r|\n)(to:|from:|cc:|bcc:)",$field_message);
if ($field_email && $field_message && $valid && !$crack){
if (mail($mail_to,$confirmationSubject,$bodymessage.$field_message,'From: '.$mail_noreply."\r\n")){
$displayForm=false;
?>
    <script language="javascript" type="text/javascript">
        alert('Your message was successfully sent. In addition, a confirmation copy was sent to your e-mail address.');
        window.location = 'contact.htm';
    </script>
<?php
        echo '<script>'.htmlspecialchars($field_message).'</script>';
      }else{ // the messages could not be sent
?>
    <script language="javascript" type="text/javascript">
        alert('Something went wrong when the server tried to send your message. This is usually due to a server error, and is probably not your fault. We apologise for any inconvenience caused. Click OK and go one step back, to see your message.');
        window.location = 'contact.htm';
    </script>
<?php
      }
    }else if ($crack){ // cracking attempt
?>
    <script language="javascript" type="text/javascript">
        alert('Your message contained e-mail headers within the message body. This seems to be a cracking attempt and the message has not been sent. Click OK and go one step back, to see your message.');
        window.location = 'contact.htm';
    </script>
<?php
    }else{ // form not complete
?>
    <script language="javascript" type="text/javascript">
        alert('Your message could not be sent. You must include both a valid e-mail address and a message. Click OK and go one step back, to see your message.');
        window.location = 'contact.htm';
    </script>
<?php
    }
  }
?>

HTML

<form action="contact.php" method="post">
  Name<br>
  <input id="phpinput" type="text" name="cf_name"><br>
  Subject<br>
  <input id="phpinput" type="text" name="cf_subject"><br>
  E-mail<span style="color: red">*</span><br>
  <input id="phpinput" type="text" name="cf_email"><br>
  Message<span style="color: red">*</span><br>
  <textarea name="cf_message"></textarea><br>
  <input class="mob_sendclear" style="font-family: bankgothic;" type="submit" value="Send">
  <input class="mob_sendclear" style="font-family: bankgothic;" type="reset" value="Clear">
</form>

問題がないとのメッセージが表示されても、まだメールを受信して​​いることを除けば、すべて問題ないように感じます...つまり、メールを送信してエラー メッセージが表示された場合でも、受信トレイにメールが受信されます。

どこで何をすべきか教えてもらえますか?

また、シンプルだが非常に安全なアンチスパム コードを配置したいと考えています。

4

1 に答える 1

-1

クライアント側を検証するだけ

jquery-validate または組み込みの検証で backbone-forms を使用します。

一般的に、これはフロントエンドであり、PHPの問題ではありません。メールのサーバー側の検証は少しやり過ぎです。なぜなら、偽の送信ごとに、ビジネス2の誰もいないサーバー側を鳴らすためです。クライアントサイドでは、私の意見です

于 2013-02-09T12:04:52.910 に答える