Page 1 of 1

How to add anti-spam code?

Posted: Wed Jun 18, 2008 6:04 am
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;
}
 
?>

Re: How to add anti-spam code?

Posted: Wed Jun 18, 2008 6:10 am
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. :)

Re: How to add anti-spam code?

Posted: Wed Jun 18, 2008 6:14 am
by ragnis12
did you mean captcha?

Re: How to add anti-spam code?

Posted: Wed Jun 18, 2008 12:16 pm
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:

Re: How to add anti-spam code?

Posted: Wed Jun 18, 2008 1:38 pm
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,…

Re: How to add anti-spam code?

Posted: Wed Jun 18, 2008 1:59 pm
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.

Re: How to add anti-spam code?

Posted: Wed Jun 18, 2008 2:24 pm
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/