Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4013392
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:21:56+00:00 2026-05-20T09:21:56+00:00

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

  • 0

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('my@gmail.com', 
                    $subject,
                    $course_title, 
                    $course_code, 
                    $course_fee,
                    $break,
                    $qual_subject_level,
                    $break,
                    $subject,
                    "From: $name <$email>");
                }
            }
            else {
                $error = 'Please fill in all the forms';
            }
        }


    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:21:56+00:00Added an answer on May 20, 2026 at 9:21 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any better way to make this query work? I'm looking for a
Is there any better way to get take a string such as (123) 455-2344
is there any way to write this foreach in linq or another better way,
Is there any better alternative for doing string formatting in VC6, with syntax checking
Are there any VC++ settings I should know about to generate better PDB files
Is there any way to stop the execution of a matlab program from the
Is there any way to stop the conflict between same class or id of
Are there any better ways to use constants in a JSP than: <%@ page
Or is there any better suited 3rd party control for this purpose?
Do I use varchar(36) or are there any better ways to do it?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.