Jump to content

Error on send


CactusProductions

Recommended Posts

Hi I have a bit of code here and I can not get it to work right!!!

 

It is a contact form from a website and the error i get is; Warning: implode() [function.implode]: Invalid arguments passed in /home/leveldte/public_html/contact-send.php on line 61

 

I have got no idar what to do.

 

<?php

function validateForm($data)

{

    $errors = array();

 

    if(empty($data['name']))

    {

        $errors['name'] = '<p class="error">You must complete the name field</p>';

    }

    elseif(!preg_match('/[-a-z\'` ]+/i', $data['name']))

    {

        $errors['name'] = '<p class="error">The name you entered is not valid</p>';

    }

 

    if(empty($data['email']))

    {

        $errors['email'] = '<p class="error">You must complete the email field</p>';

    }

    elseif(!filter_var($data['email'], FILTER_VALIDATE_EMAIL))

    {

        $errors['email'] = '<p class="error">The email address you entered is not valid</p>';

    }

 

    if(empty($data['message']))

    {

        $errors['message'] = '<p class="error">You must enter a message</p>';

    }

 

    return $errors;

}

 

 

function processTheForm($to)

{

    $result = array();

    if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST['middle-name']))

    {

        $errors = validateForm($_POST);

        $_POST['message'] = strip_tags($_POST['message']);

        $subject= strip_tags($_POST['subject']);

 

        if(empty($subject))

        {

            $subject = 'Message from '.$_POST['name'];

        }

 

        if(empty($errors))

        {

            $headers = array(

                'Content-type'=>'text/html',

                'From'=>"{$_POST['name']}<{$_POST['email']}>",

                'To'=>$to,

                'Date'=>date('r')

            );

 

            $mailTpl = file_get_contents('mail-template.tpl.php');

            $mailTpl = str_replace(array('[name]', '', '[message]'),

                array($_POST['name'], $_POST['email'], $_POST['message']), $mailTpl);

 

 

            if(mail($to, $subject, $mailTpl, implode("\r\n", $headders)))

            {

                unset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['message']);

                $result['mail_error'] = false;

            }

            else

            {

                $result['mail_error'] = true;

            }

        }

 

        $result['errors'] = $errors;

    }

 

    return $result;

}

 

 

Thanks for your help everyone!

 

Daniel

 

Link to comment
https://forums.phpfreaks.com/topic/216696-error-on-send/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.