Frage

One of my Magento CE 1.7 sites contact form is being spammed by human spam farms thus bypassing the Google reCaptcha implemented on such forms. The rate of spam received is an exorbitant 300 emails a day that have successfully verified the captcha.

As the contact form is being used, no sender ip address is being emanated with the email, hence I need help and guidance on how to obtain the user IP and have this included with the spam contact email that I receive.

The idea is to ban the IPs that are being used for spamming.

The php call to get the user IP

echo Mage::helper('core/http')->getRemoteAddr(true);

How can I use this within the contact form and have the IP submitted with the contact form contact.

I appreciate all the help.

With best regards

Fab

War es hilfreich?

Lösung

Andrew,

Thanks a lot.

The correct IP showed up with this adjustment over your code:

public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
    $translate = Mage::getSingleton('core/translate');
    /* @var $translate Mage_Core_Model_Translate */
    $translate->setTranslateInline(false);
    try {
        $postObject = new Varien_Object();
        $postObject->setData($post);
        // Add the IP..
        $postObject->setData(
            'ip', 
            $_SERVER['REMOTE_ADDR'] 
        );

Thanks a lot once again

Andere Tipps

You can simply override the contacts controller:

Mage_Contacts_IndexController

Just modify the post action:

public function postAction()
{
    $post = $this->getRequest()->getPost();
    if ( $post ) {
        $translate = Mage::getSingleton('core/translate');
        /* @var $translate Mage_Core_Model_Translate */
        $translate->setTranslateInline(false);
        try {
            $postObject = new Varien_Object();
            $postObject->setData($post);
            // Add the IP..
            $postObject->setData(
                'ip', 
                $_SERVER['REMOTE_ADDR']
                //Mage::helper('core/http')->getRemoteAddr(true)
            );

            // .. rest un changed..

Now you will need to update the email template:

Go to System → Transactional E-mails in the Magento Admin section.

2) ‘Add New Template’

3) From the ‘Template’ dropdown box select "Contact Form", Click "Load Template"

Now Modify the template to add in the new field:

Name: {{var data.name}}
E-mail: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}
IP Address: {{var data.ip}}

Go to System → Configuration → Contacts

Select your new in the "Email Template" dropdown box.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top