recommendation for a good mail form?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Can anyone recommend a simple PHP script for taking the contents of
a form and emailing it to an address defined within the PHP script?  I
have downloaded a couple via Google, but they're not quite what I'm
looking for.

Thanks for your advice, - Dave

Re: recommendation for a good mail form? wrote:
Quoted text here. Click to load it

IMHO, the following works well as an "include file" for various Contact
Us forms on my client's web sites.

function valid_email($email)

       return false;


       return true;


    return false;

$opts['admin_email'] = '';

$opts['admin_name'] = 'Some One';

$opts['owner_email'] = '';

$msg = '';

// Disallow certain HTML INPUT names from appearin in email messages

$omit_field_name_array = array('s', 'submit');


    $subj = str_replace('www.', '', $_SERVER['HTTP_HOST']).' web site


while(list($key, $val) = each($_POST)){

    if($val != '' && !in_array($key, $omit_field_name_array)){

       $new_key = str_replace('_', ' ', $key);

       $msg .= ucwords($new_key).':


    $$key = stripslashes(trim(strip_tags($val)));

    # Debug
    # echo "\n".$key.' = '.$val.'<br>';
    # exit;


$lf = isset($_SERVER["COMSPEC"])
    && stristr($_SERVER["COMSPEC"], 'windows')
    ? "\r\n" : "\n";

if($msg != ''){

    $msg .= 'Submitted: '.date('r')."\n";


       $hdr  =     'From: <'.$email.'>'."$lf"
                .'Reply-To: '.$email."$lf"
                .'Return-Path: '.$email."$lf"
                .'X-Mailer: PHP '.phpversion()."$lf"
                .'X-Priority: 3'."$lf"
                .'X-Sender: '.$email;

       $hdr  =     'From: "'.$opts['admin_name'].'"
                .'Reply-To: '.$opts['admin_email']."$lf"
                .'Return-Path: '.$opts['admin_email']."$lf"
                .'X-Mailer: PHP '.phpversion()."$lf"
                .'X-Priority: 3'."$lf"
                .'X-Sender: '.$opts['admin_email'];


    $msg .= "--Site

     $opts['owner_email'] != $opts['admin_email'] ? $hdr .= "BCC:
" : '';

    $sent = @mail($opts['owner_email'], $subj, $msg, $hdr);

    if(!($res = @mysql_query(sprintf("INSERT INTO feedback (name, email,
subj, comments)
       VALUES ('%s', '%s', '%s', '%s')",
          $email, addslashes($subj),

       $opts['admin_msg'] = $_SERVER['PHP_SELF'].' did not insert
feedback on '.$_SERVER['HTTP_HOST'];



Site Timeline