Jump to content

Recommended Posts

Hello there. I've been having trouble with an email form. Can't find the problem really. I've tested so many times, tried different ifs to see where the problem comes from. It turned out its alway the last ELSE. The one that doesnt have explanation to me. Here we go:

if(isset($_GET['send'])) {

    $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    //$email = htmlentities($email,ENT_QUOTES);
    $body=stripslashes($_POST['body']);
    $date = date("F j, Y, g:i a");
    $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM');
    $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body);
    $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], "."));

    if ($email && $body && $valid && !$spam) {
        if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) {

            echo '<p>'.$thanks.'</p>';
            $email='';
            $body='';
        }
        else {
            echo '<p>'.$error.'</p>';
            $email='';
            $body='';
        }
    }
    else if ($spam) {
            echo '<p>'.$spamattack.'</p>';
            $email='';
            $body='';
        }
        else {
            echo'<p><strong>'.$fillin.'</strong></p>';
            $email='';
            $body='';
        }

    }

Link to comment
https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/
Share on other sites

string(13) "test@test.com" string(24) "rrrr " int(1) int(0)

I've checked so many times.

<form method="post" action="contacts.php?send">
                                <label for="email">Email:</label> <input name="email" type="text" value="<?php echo htmlspecialchars($email); ?>" size="30"><br />
                                    <label for="body"> Message:</label><br />
                                    <textarea name="body" rows="15" cols="40"><?php echo htmlspecialchars($body); ?>
                                    </textarea><br />
                                    <input type="submit" value="Send" name="send"/>
                            </form>

What i meant was i tried different ifs. i removed the mail() function and added only if (!$email) etc. I keep all the results at home, a couple of hours later ill post them out. Actually if i remember correct i had problems with $valid...once i made it to the final ELSE that was placed for any other mistake. Ill post more tonight.

 

your indenting is off .. fixed code:

 

<?php
if(isset($_GET['send'])) {

    $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    //$email = htmlentities($email,ENT_QUOTES);
    $body=stripslashes($_POST['body']);
    $date = date("F j, Y, g:i a");
    $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM');
    $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body);
    $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], "."));

    if ($email && $body && $valid && !$spam) {
        if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) {

            echo '<p>'.$thanks.'</p>';
            $email='';
            $body='';
        }
        else {
            echo '<p>'.$error.'</p>';
            $email='';
            $body='';
        }
    }
    else if ($spam) {
	echo '<p>'.$spamattack.'</p>';
	$email='';
	$body='';
    }
    else {
	echo'<p><strong>'.$fillin.'</strong></p>';
	$email='';
	$body='';
    }

}
?>

 

so, this is not working for you:

 

if ($email && $body && $valid && !$spam) {

 

check through those $vars to see what's going on.  check $valid as '09_az..AZ@host.dOMain.cOM' this might not be working for you.

so, this is not working for you:

 

if ($email && $body && $valid && !$spam) {

 

check through those $vars to see what's going on.  check $valid as '09_az..AZ@host.dOMain.cOM' this might not be working for you.

If you read the thread you'll see that I already asked the OP to show us those values. If you check the output given you'll also see that row evaluates as true. Meaning that the problem appears to be with the call to mail. Having said that I can't see any reason it would fail, assuming the server is setup correctly. I'd probably add "\r\n" to the end of the header, but I don't believe it's required after the last header item. The script as is doesn't contain values for $error, $thanks, $spamattack or $fillin. Which would make it fairly difficult to calculate exactly which block is being entered.

 

Hello everyone, thanks for the replies!

with this:

$email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    //$email = htmlentities($email,ENT_QUOTES);
    $body=stripslashes($_POST['body']);
    $date = date("F j, Y, g:i a");
    $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM');
    $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body);
    $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], "."));

    if ($email && $body && $valid && !$spam) {
        if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) {.....

 

i got this error:

Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:.... on line 95

 

We encountered problem while sending your message!

 

The problem is probably due to a server error.

We appologise for the inconvinience.

Please try again.

 

with

    //$email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    $email = htmlentities($email,ENT_QUOTES);
    $body=stripslashes($_POST['body']);
    $date = date("F j, Y, g:i a");
    $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM');
    $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body);
    $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], "."));

    if ($email && $body && $valid && !$spam) {
        if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) {

i got

Notice: Undefined variable: email in C:\wamp\www\torch\web\contacts.php on line 87

 

Please fillin valid email address

 

I honestly got totally lost in the different tests...

 

if(isset($_GET['send'])) {

    $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  //  $email = htmlentities($email,ENT_QUOTES);
    $body=stripslashes($_POST['body']);
    $date = date("F j, Y, g:i a");
$valid = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
//$valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-)([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM');
    $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body);
    $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], "."));

    if ($email && $body && $valid && !$spam) {
        if (mail( $to, "Feedback Form Results", $body, "From: $email" )) {

 

fails on $valid

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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