Dave3765 Posted October 26, 2007 Share Posted October 26, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/ Share on other sites More sharing options...
ToonMariner Posted October 26, 2007 Share Posted October 26, 2007 if (preg_match('/ href=/',$mail->Body) { echo 'OI! Armstrong! NO! You not in your luna module now sunshine!'; } else { $mail->Send(); } Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378584 Share on other sites More sharing options...
Dave3765 Posted October 26, 2007 Author Share Posted October 26, 2007 OI! Armstrong! NO! You not in your luna module now sunshine! LOL - thanks for the reply. What exactly does this check for and where should I put it? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378587 Share on other sites More sharing options...
Dave3765 Posted October 26, 2007 Author Share Posted October 26, 2007 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> '); } Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378597 Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 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. } Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378626 Share on other sites More sharing options...
ToonMariner Posted October 26, 2007 Share Posted October 26, 2007 @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. Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378659 Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 @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. Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378671 Share on other sites More sharing options...
Dave3765 Posted October 26, 2007 Author Share Posted October 26, 2007 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. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/74875-solved-phpmailer-question-how-can-i-check-for-links-in-message/#findComment-378675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.