Code for small mail sender form

I finished to style my e-mail text box and submit button (here).

Now I need help for the PHP part, to get the submitted addresses to my mailbox.

Here is my attempt:

<?php
/* Set e-mail recipient */
$myemail = "mail@ilcontadinobio.it";

/* Check all form inputs using check_input function */
$subject = "New e-mail address from ilcontadinobio.it";
$email = check_input($_POST['email']);

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "


E-mail: $email
Subject: $subject

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: azienda.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>

It doesn’t seem working. Any address I type in triggers the function show_error.
Is there anything wrong with preg_match?

The code is not my doing. I can publish the original one if required.

Waiting for clarifications.
Thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.