How to add anti-spam code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mark104
Forum Newbie
Posts: 4
Joined: Wed Jun 18, 2008 5:44 am

How to add anti-spam code?

Post by mark104 »

How to add anti-spam code to that?

Code: Select all

<?php
defined( '_VALID_WT' ) or die( 'Direct Access to this location is not allowed.' );
 
$content='';
 
switch($task) {
    case "sendmail":
        $content.=sendmail( $option );
        break;
    default:
        $content.=contactpage( $option, $Itemid );
        break;
}
 
function contactpage( $option, $Itemid ) {
    global $database, $mainframe, $cur_template, $lang, $Itemid;
 
        $tfile = 'templates/'.$cur_template.'/components/com_contact.html';
        $ffile = 'templates/'.$cur_template.'/components/com_contact.inc';
        if (file_exists($tfile)) {
            if ($tpl_main = temp_load($tfile)) {
 
                $database->setQuery( "SELECT value FROM #__globals WHERE name='contact_txt' LIMIT 1" );
                $txt = null;
                $database->loadObject( $txt );
                
                $contact['_CONTACT_FORM_TOP'] = $txt->value;
 
                if (file_exists($ffile)) {
                    include $ffile;
                }
                temp_subs($tpl_main, "contact", $contact);
                temp_done($tpl_main);
 
                $ret .= temp_out($tpl_main);
            }
        } else {
            $ret.='Can\'t find file '.$tfile;
        }
        return $ret;
}
 
function sendmail( $option ) {
    global $database, $Itemid, $lang;
    global $mainframe;
    $ret = '';
 
    $ypost = trim( mosGetParam( $_POST, 'ypost', '' ) );
    $email = trim( mosGetParam( $_POST, 'email', '' ) );
    $contact = trim( mosGetParam( $_POST, 'contact', '' ) );
 
    $database->setQuery( "SELECT value FROM #__globals WHERE name='contact_recipient' LIMIT 1" );
    $recipient = null;
    $database->loadObject( $recipient );
    $email_to=$recipient->value;
    $database->setQuery( "SELECT value FROM #__globals WHERE name='contact_subject' LIMIT 1" );
    $sub = null;
    $database->loadObject( $sub );
    $subject=$sub->value;
    
    $mails=explode(";",$email_to);
 
    $m= new Mail; // create the mail
    $m->From( $mainframe->getCfg('sitename').'<'.$mails[0].'>' );
    $m->To( $mails );
    $m->Subject( $subject );
    $m->Content_type( "text/html" );
    
    $message = _CONTACT_POST.': '.$ypost.'<br/>';
    $message .= _CONTACT_MAIL.': '.$email.'<br/>';
    $message .= _CONTACT_INFO.': '.$contact.'<br/>';
    
    // set the body
    if ($lang==4) {
        $m->Body( $message, "windows-1251" );        
    } else {
        $m->Body( $message, "iso-8859-1" );        
    }
 
    $m->Send();        // send the mail
 
    $ret.='<script> alert("'._THANK_MESSAGE.'"); document.location.href=\''.sefRelToAbs("index.php?option=$option&Itemid=$Itemid&lang=$lang").'\';</script>';
    
    return $ret;
}
 
function is_email($email){
    $rBool=false;
 
    if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)){
        $rBool=true;
    }
    return $rBool;
}
 
?>
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to add anti-spam code?

Post by WebbieDave »

You'll need to provide way more detail on what you're trying to do. Also, include what you've tried and the results of those tries.

You can't throw down 100 lines of code and expect many to rummage through it. We're here to help you, not work for you. :)
ragnis12
Forum Newbie
Posts: 12
Joined: Tue Jun 17, 2008 4:14 am

Re: How to add anti-spam code?

Post by ragnis12 »

did you mean captcha?
mark104
Forum Newbie
Posts: 4
Joined: Wed Jun 18, 2008 5:44 am

Re: How to add anti-spam code?

Post by mark104 »

Yes i mean CAPTCHA
But please people help i don't know how i can add it, because the whole code php, if it was html i think i could do it by myself but please HELP :cry:
User avatar
Greenconure
Forum Commoner
Posts: 30
Joined: Mon Jun 16, 2008 8:19 am

Re: How to add anti-spam code?

Post by Greenconure »

mark104 wrote:Yes i mean CAPTCHA
But please people help i don't know how i can add it, because the whole code php, if it was html i think i could do it by myself but please HELP :cry:
Check out reCAPTCHa -> http://recaptcha.net/whyrecaptcha.html
It's probably safer and easier to use reCAPTCHA, but if you want to do it yourself you should look into some of the basics, like image creation (using gd, etc), validation,…
mark104
Forum Newbie
Posts: 4
Joined: Wed Jun 18, 2008 5:44 am

Re: How to add anti-spam code?

Post by mark104 »

Check out reCAPTCHa -> http://recaptcha.net/whyrecaptcha.html
It's probably safer and easier to use reCAPTCHA, but if you want to do it yourself you should look into some of the basics, like image creation (using gd, etc), validation,…
The problem is that I don' know on what lines I should add those codes which are given on recaptcha.
User avatar
Greenconure
Forum Commoner
Posts: 30
Joined: Mon Jun 16, 2008 8:19 am

Re: How to add anti-spam code?

Post by Greenconure »

mark104 wrote:
Check out reCAPTCHa -> http://recaptcha.net/whyrecaptcha.html
It's probably safer and easier to use reCAPTCHA, but if you want to do it yourself you should look into some of the basics, like image creation (using gd, etc), validation,…
The problem is that I don' know on what lines I should add those codes which are given on recaptcha.
Read this -> http://recaptcha.net/plugins/php/
Post Reply