Jump to content

[SOLVED] PHPMailer Question - How Can I Check For Links In Message?


Recommended Posts

Hey Guys,

 

I sometimes get emails that are not technically spam, but are defiantly not wanted and throw off my conversion ratios. The one common thing about all of these unwanted emails is that they contain links in the form of URL's or email addresses - or both. None of the valid ones contain links. I still need to receive the PHPmailer confirmation about these emails, but I want to direct them to a different location with another window.location function to preserve my conversion tracking and keep it as accurate as possible.

 

Here is a chunk of code form the contact page on my site that send a confirmation email to the person who filled out the form. I have another piece like this which sends a confirmation email to me:

 

$mail = new PHPMailer();
    $mail->SetLanguage("en", "inc/");
    $mail->From = "bob@bob.com";
    $mail->FromName = "Admin";
    if ($test == 'FAIL') {
	  $mail->AddAddress("spam@bob.com");
    } else {
	  $mail->AddAddress("$email");
	}
    $mail->WordWrap = 50;
    $mail->IsHTML(true);
    $mail->Subject = "Your Enquiry, $name";
	  $mail->Body = "HTML of message goes here";
    $mail->Send();

    echo('
<script type="text/javascript">
<!--
window.location = "URL of my conversion page goes here"
//-->
</script>
');

 

The HTML of my form for the area that I would like to check for links in is below:

 

<textarea name="text" rows="8" cols="70" class="text" wrap><?=$echo?></textarea>

 

 

Any ideas?

 

If you need more code just tell me what.

 

Thanks!  8)

Does this check the $mail->Body string for instances of href= ?

 

The section I need to check is the part that the user fills out on my site, which is the value of the text field 'text' and has been stored in the string $text.

 

Would it work if I modified it to this?:

 

$mail = new PHPMailer();
    $mail->SetLanguage("en", "inc/");
    $mail->From = "bob@bob.com";
    $mail->FromName = "Admin";
    if ($test == 'FAIL') {
	  $mail->AddAddress("spam@bob.com");
    } else {
	  $mail->AddAddress("$email");
	}
    $mail->WordWrap = 50;
    $mail->IsHTML(true);
    $mail->Subject = "Your Enquiry, $name";
	  $mail->Body = "HTML of message goes here";
    $mail->Send();

if (preg_match('/ href=/',$text)
{
echo ('
<script type="text/javascript">
<!--
window.location = "URL of my FAKE conversion page goes here"
//-->
</script>
');
}
else
{
    echo('
<script type="text/javascript">
<!--
window.location = "URL of my conversion page goes here"
//-->
</script>
');
}

Let me through this out there, why check for href=?

 

I would check for http:// and or www.  as those generally signify a link, which broadens your search and chances of catching a spammer is greater.

 

To do that you do not need preg_match, simply stristr would work (make sure you use the === to check for false.

 

$mail = new PHPMailer();
    $mail->SetLanguage("en", "inc/");
    $mail->From = "bob@bob.com";
    $mail->FromName = "Admin";
    if ($test == 'FAIL') {
	  $mail->AddAddress("spam@bob.com");
    } else {
	  $mail->AddAddress("$email");
	}
    $mail->WordWrap = 50;
    $mail->IsHTML(true);
    $mail->Subject = "Your Enquiry, $name";
	  $mail->Body = "HTML of message goes here";

    if (stristr($text, "www.") !== false || stristr($text, "http://") !== false) {
      die("We do not like spammers");
    }else {
        $mail->Send(); // only send if they are not a spammer.
    }

@premiso ???

 

href= is FAR MORE LIKELY to be a link or mail to as that is what is needed! - otherwise you'd match urls to images that shoudl be displayed....

 

@dave

If you only need it on the text the user enters then run the regex on the text they enter rather than the whole body of the email.

@premiso ???

 

href= is FAR MORE LIKELY to be a link or mail to as that is what is needed! - otherwise you'd match urls to images that shoudl be displayed....

 

It all depends on what the email form is for. Most of my contact forms I only allow at most 1 link, any more is considered spam. Reason being is that if someone is reporting a link, it needs to be allowed. As I most my emails are sent as text and not html, no images should be included. That and my email converts http:// and www. to links, which I do understand certain places like AOL needs the herf=.

 

It all depends on what he needs/is needed. I was just throwing out a suggestion/alternative solution.

I have tweaked the code and got a solution which I have tested, and it works.

 

I used this:

 

if (stristr($text, "www.") !== false || stristr($text, "@") !== false) {
    echo('
<script type="text/javascript">
<!--
window.location = "URL of FAKE conversion page"
//-->
</script>
');
    }else {
    echo('
<script type="text/javascript">
<!--
window.location = "URL of REAL conversion page"
//-->
</script>
');
    }

 

I still needed to receive the email confirmations, but I just wanted to redirect the user to a different page (one that didn't contain my GA tracking code) to preserve the conversion ratio.

 

I used the filters of "www." and "@" because they were the 2 things most commonly used by spammers on my site. Regular users imputed plain text 100% of the time.

 

A big THANK YOU to ToonMariner and premiso for helping me out with this - much appreciated. :D

 

Thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.