Formmail

    Date: 02/16/06 (PHP Community)    Keywords: php, browser, html

    Hello all. I'm having some troubles with a formmail script and cannot get the help I need anywhere. I found this community and thought I'd give it a try. This is a script I have used several times before and have had no problems with it. For some reason, I cannot get it to work this time. I don't have a lot of knowledge about PHP, and this is a free script that I tried. I liked it because it worked, but now it's just frustrating me.


    This is the HTML form I set up:

    < form method="post" action="../php_uploads/comment.php">
    Name: < input type="text" name="name" size="30" maxlength="30" />
    Address: < input type="text" name="address" size="30" maxlength="30" />
    City: < input type="text" name="city" size="20" maxlength="20" /> State: < input type="text" name="state" size="10" maxlength="10" />
    Zip: < input type="text" name="zip" size="15" maxlength="15" />
    Phone: < input type="text" name="phone" size="20" maxlength="20" />
    Email: < input type="text" name="email" size="30" maxlength="30" />
    Comments: < textarea name="comments" rows="5" cols="30">
    < input name="submit" type="submit" value="Submit Comments">
    < input name="reset" type="reset" value="Clear Comments">

    This is my formmail code:

    $recipient = 'brandi @ wikedawsum.com';
    $subject = 'Perfect Pools - Comments Form';
    $form_url = 'http://perfectpools.wikedawsum.com/pages/contact.html';

    $msg = "---------------\n";
    $msg .= "$subject\n";
    $msg .= "---------------\n\n";
    $msg .= "Name: $_POST[name]\n";
    $msg .= "Address: $_POST[address]\n";
    $msg .= "City: $_POST[city]\n";
    $msg .= "State: $_POST[state]\n";
    $msg .= "Zip: $_POST[zip]\n";
    $msg .= "Phone: $_POST[phone]\n";
    $msg .= "Email: $_POST[email]\n";
    $msg .= "Comments: $_POST[comments]\n";

    $error_required = '< p>It appears you forgot to enter either your name, your phone number or your email address. Please press the BACK button in your browser and try again.< /p>'; <- This is the error msg I keep getting.

    $error_email = '< p>Oops, it appears that the email address you filled in is not a valid one. Please press the back button on your browser and try again. Please check carefully that you filled in all information in the right fields!< /p>';

    $success_message = '< p>Your form has been sent. We will contact you in the next few business days regarding your inquiries. Thank you.< /p>';

    if ($header ==""){
    $use_headers ='0';
    $header = '';
    } else {$use_headers ='1';}
    if ($footer ==""){
    $use_footers ='0';
    $footer = '< div align="center">< a href="http://codegrrl.com/" target="_blank">Powered by NL-PHPMail< /a>< /div>< /body>< /html>';
    } else {$use_footers ='1';}

    function is_valid_email ($address) {
    return (preg_match(
    '/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+'.
    '@'.
    '([-0-9A-Z]+\.)+' .
    '([0-9A-Z]){2,4}$/i',
    trim($address)));
    }
    function is_valid_email_eregi ($address) {
    return (eregi(
    '^[-!#$%&\'*+\\./0-9=?A-Z^_`{|}~]+'.
    '@'.
    '([-0-9A-Z]+\.)+' .
    '([0-9A-Z]){2,4}$',
    trim($address)));
    }

    if (!isset($req1) || !isset($req2) || !isset($req3)) {
    header( "Location: $form_url" ); }

    elseif (empty($req1) || empty($req2) || empty($req3)) {

    if ($use_headers =="0"){
    echo "$header";
    } else { include ("$header"); }
    ?>
    < h2>Error< /h2>
    < ?=$error_required?>


    < ?
    if ($use_footers =="0"){
    echo "$footer";
    } else { include ("$footer"); }
    }
    else {

    $f_email = $_POST[email];
    $f_email = strtolower(trim($f_email));
    if (is_valid_email($f_email)) {
    $msg .= "\n\n---------------\n";
    $msg .= "NL-PHPMail v1.5 - http://codegrrl.com/\n";
    $msg .= "---------------\n\n";

    $mailheaders = "MIME-Version: 1.0 \n";
    $mailheaders .= "Content-type: text/plain; charset=iso-8859-1 \n";
    $mailheaders .= "From: \"$_POST[email]\" <$_POST[email]> \n";
    $mailheaders .= "Reply-To: \"$_POST[email]\" <$_POST[email]> \n";
    $mailheaders .= "X-Priority: 3 \n";
    $mailheaders .= "X-MSMail-Priority: High \n";
    $mailheaders .= "X-Mailer: PHP4";

    mail($recipient, $subject, $msg, $mailheaders);

    if ($use_headers =="0"){
    echo "$header";
    } else { include ("$header"); }
    ?>
    < h2>Thank You, < /h2>
    < ?=$success_message?>

    < ?
    if ($use_footers =="0"){
    echo "$footer";
    } else { include ("$footer"); }
    } else {
    if ($use_headers =="0"){
    echo "$header";
    } else { include ("$header"); }
    ?>
    < h2>Error< /h2>
    < ?=$error_email?>
    < ?
    if ($use_footers =="0"){
    echo "$footer";
    } else { include ("$footer"); }

    My problem is that everytime I hit the submit button I get my $error_required message (which I bolded up there). I've tried rewriting the script and the form, but nothing seems to work. I'm running out of ideas and am starting to get frustrated. Maybe a new pair of eyes will help?

    I apologize for the code being so long. I just wanted to make sure I didn't miss anything. Thanks in advance for any help you guys can provide. I'm also open to suggestions on any other ways to do this more efficiently. I'm sure you guys know a lot more about this than I do. Thanks again!

    Source: http://community.livejournal.com/php/415280.html

« The MD5 Form || Dammit Jim, we're... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home