Help Form PHP Help

Asked

Viewed 36 times

-2

I have the following code:

<?php

// Do not edit this if you are not familiar with php
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post) {
    function ValidateEmail($email){

        $regex = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^";
        $eregi = preg_replace($regex,'', trim($email));

        return empty($eregi) ? true : false;
    }

    $name = stripslashes($_POST['ContactName']);
    $to = trim($_POST['to']);
    $email = strtolower(trim($_POST['ContactEmail']));
    $subject = stripslashes($_POST['subject']);
    $message = stripslashes($_POST['ContactComment']);
    $error = '';
    $Reply=$to;
    $from=$to;

    // Check Name Field
    if(!$name) {
        $error .= 'Please enter your name.<br />';
    }

    // Checks Email Field
    if(!$email) {
        $error .= 'Please enter an e-mail address.<br />';
    }
    if($email && !ValidateEmail($email)) {
        $error .= 'Please enter a valid e-mail address.<br />';
    }

    // Checks Subject Field
    if(!$subject) {
        $error .= 'Please enter your subject.<br />';
    }

    // Checks Message (length)
    if(!$message || strlen($message) < 3) {
        $error .= "Please enter your message. It should have at least 5 characters.<br />";
    }

    // Let's send the email.
    if(!$error) {
        $messages="From: $email <br>";
        $messages.="Name: $name <br>";
        $messages.="Email: $email <br>";    
        $messages.="Message: $message <br><br>";
        $emailto=$to;

        $mail = mail($emailto,$subject,$messages,"from: $from <$Reply>\nReply-To: $Reply \nContent-type: text/html");    

        if($mail) {
            echo 'success';
        }
    } else {
        echo '<div class="error">'.$error.'</div>';
    }

}
?>

Can anyone tell me where I should enter my email address to receive the data from this form?

1 answer

0

I see you don’t know the function well mail php

mail(string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]]);

$to = Recipient of the email in question

In your code $emailto=$to; refers to the receiver, $tois coming from $_POST from another form

Can anyone tell me where I should enter my email address to receive the data from this form?

You can send a copy to you by placing your email as one of the recipients:

$to=trim($_POST['to']).',';
$to.='[email protected]';

Or you can change to send only to your email, in this case it would be interesting to remove the input[name='to'] form that sends information to this email

$to='[email protected]';

Simply changing line 16 of your code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.