PHPMailer 表单帮助

发布于 2024-10-19 04:53:07 字数 2182 浏览 5 评论 0原文

有没有更好的方法来阻止垃圾邮件通过我的 phpmailer 脚本?

另外,我将如何添加格式,以便它在发送到电子邮件时更具可读性,例如断行

我希望我的 php 语法是正确的 - 因为我不懂 PHP。

<?php
        # bool has_injection (String $var, [String $var, ...])
        function has_injection () {
            $values = func_get_args();
            for ($i=0, $count=func_num_args(); $i<$count; $i++) {
                if ( stristr($values[$i], "%0A") || stristr($values[$i], "%0D") || stristr($values[$i], "\\r") || stristr($values[$i], "\\n") 
                    || stristr($values[$i], "Bcc") || stristr($values[$i], "Content-Type") ) {
                    return true;
                }
            }
            return false;
        }

        $error = '';
        if (isset($_POST) && count($_POST)>0) {
            # The form has been submitted
                $course_title = $_POST['course_title'];
                $course_date = $_POST['course_date'];
                $course_code = $_POST['course_code'];
                $course_fee = $_POST['course_fee'];
                $break .= "\n";
                $qual_subject_level = $_POST['qual_subject_level'];
                $break .= "\n";
                $email = $_POST['email'];

            if ($name && $email && $subject) {
                if (has_injection($name, $email, $subject)) {
                    # You've got another spammer at work here
                    $error = 'No spamming';
                    exit(0);
                }
                else {
                    # It's safe to send the message
                    mail('[email protected]', 
                    $subject,
                    $course_title, 
                    $course_code, 
                    $course_fee,
                    $break,
                    $qual_subject_level,
                    $break,
                    $subject,
                    "From: $name <$email>");
                }
            }
            else {
                $error = 'Please fill in all the forms';
            }
        }


    ?>

Is there any better way to stop spam coming through on my phpmailer script?

Also how would I go about adding formatting to this so its more readable when it gets sent through to email e.g. break lines

I hope my php syntax is correct - as i do not understand PHP.

<?php
        # bool has_injection (String $var, [String $var, ...])
        function has_injection () {
            $values = func_get_args();
            for ($i=0, $count=func_num_args(); $i<$count; $i++) {
                if ( stristr($values[$i], "%0A") || stristr($values[$i], "%0D") || stristr($values[$i], "\\r") || stristr($values[$i], "\\n") 
                    || stristr($values[$i], "Bcc") || stristr($values[$i], "Content-Type") ) {
                    return true;
                }
            }
            return false;
        }

        $error = '';
        if (isset($_POST) && count($_POST)>0) {
            # The form has been submitted
                $course_title = $_POST['course_title'];
                $course_date = $_POST['course_date'];
                $course_code = $_POST['course_code'];
                $course_fee = $_POST['course_fee'];
                $break .= "\n";
                $qual_subject_level = $_POST['qual_subject_level'];
                $break .= "\n";
                $email = $_POST['email'];

            if ($name && $email && $subject) {
                if (has_injection($name, $email, $subject)) {
                    # You've got another spammer at work here
                    $error = 'No spamming';
                    exit(0);
                }
                else {
                    # It's safe to send the message
                    mail('[email protected]', 
                    $subject,
                    $course_title, 
                    $course_code, 
                    $course_fee,
                    $break,
                    $qual_subject_level,
                    $break,
                    $subject,
                    "From: $name <$email>");
                }
            }
            else {
                $error = 'Please fill in all the forms';
            }
        }


    ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2024-10-26 04:53:07

我使用的一个是有一个文本区域并使用您的 .css 文件来显示:无大多数机器人不会读取 css,因此认为文本框已显示,如果其中有内容,则它是一个机器人,如果没有则发送你的电子邮件。

EGCSS
.antiBot{display:none};

HTML

PHP

<?php
if($_REQUEST['antibot'] == ""){
  // send your email
}else{
  // bot using your system
}
?>

如何更改名称或机器人将能够注意到它是一个陷阱并只需很少的工作就可以解决这个问题,而无需解析您网站的 CSS 文件

因此,在您的情况下,只需将上面的 if 放在您的代码周围,就像电子邮件的格式一样,如果其纯文本使用双引号和 \n (换行符)但是它在单引号中不起作用。

One i use is have a text area and use your .css file to display:none it most bots dont read the css and thus think that the text box is shown and if it has content in it it's a bot if it does not then send your email.

E.G CSS
.antiBot{display:none};

HTML
<input type="text" class="antiBot" name="antibot" value="" />

PHP

<?php
if($_REQUEST['antibot'] == ""){
  // send your email
}else{
  // bot using your system
}
?>

How ever change the name or bot will get be able to notice its a trap and will get around it with little work insted of having to parse the CSS file for your site

So in your case just rap the if above around your code as for formatting of an email if its plain text use dubble quotes and \n (newline) but it wont work in single quotes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文