check to see if an email given contains certains a phrase

A

Anonymous

Guest
Hi

I keep getting spam from my contact form http://www.art86.org/contactus.php where the sender is inserting something like bendfgfsd@art86.org.

I've looked for a way of comparing the &youremail string given to see if it contains 'art86.org' and, if so, reject it with an error message but cannot find out how to compare part of the string to do this.

Any suggestions would be helpful please

Thanks
 
diveability said:
Hi

I keep getting spam from my contact form http://www.art86.org/contactus.php where the sender is inserting something like bendfgfsd@art86.org.

I've looked for a way of comparing the &youremail string given to see if it contains 'art86.org' and, if so, reject it with an error message but cannot find out how to compare part of the string to do this.

Any suggestions would be helpful please

Thanks

Yeah, use https://www.google.com/recaptcha/about/
 
Strider64 said:
diveability said:
Hi

I keep getting spam from my contact form http://www.art86.org/contactus.php where the sender is inserting something like bendfgfsd@art86.org.

I've looked for a way of comparing the &youremail string given to see if it contains 'art86.org' and, if so, reject it with an error message but cannot find out how to compare part of the string to do this.

Any suggestions would be helpful please

Thanks

Yeah, use https://www.google.com/recaptcha/about/

I'm already using a captcha to stop bots. What I need to do is somehow examine the $youremail string, that the sender enters, and, if it contains my website eg ????@art86.org, then the code intercepts it and sends a Fail to send message to the originator.

If someone could help with the code to do this that would be great thanks
 
To compare part of a string in PHP, you can use the strpos() function, which returns the position of the first occurrence of a substring within a string. If the substring is not found, it returns false.
Here's an example of how you can use strpos() to check if the email address contains the domain "art86.org" and reject it with an error message:
<?php
$youremail = $_POST['youremail']; // Assuming you're getting the email address from a form field

$domain = 'art86.org';

if (strpos($youremail, $domain) !== false) {
// Email address contains the domain "art86.org"
// Reject the email and display an error message
echo "Invalid email address. Please use a different email domain.";
exit; // Stop further processing
}

// Proceed with the rest of your code if the email is valid
// ...
?>
In this example, strpos($youremail, $domain) checks if the substring $domain ("art86.org") is found within the $youremail string. If the substring is found, strpos() will return a non-false value, and the email address will be rejected with the error message.

Note that strpos() is case-sensitive. If you want a case-insensitive comparison, you can use stripos() instead.

Remember to validate and sanitize the email address input thoroughly to ensure security and prevent other forms of spam or abuse. Additionally, implementing additional measures such as CAPTCHA or other anti-spam techniques can further enhance the security of your contact form.
 
Back
Top