How to make the entered information in a form send to an email current php form not properly working

I’ve been trying to get a html and php file to work but every time it sends the email to my inbox it shows this: Hello!

Your subscribe form has been submitted by:

E-mail:

End of message
That is the layout I want but the E-mail: bit doesn’t have an email next to it.
Here’s my code:
Php:

<?php
/* Set e-mail recipient */
$myemail  = "email@example.com";

/* Check all form inputs using check_input function */

$email    = check_input($_POST['email']);

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))


/* Let's prepare the message for the e-mail */
$message = "Hello!

Your subscribe form has been submitted by:

E-mail: $email



End of message
";

/* Send the message using mail() function */
mail($email);

/* Redirect visitor to the thank you page */
header('Location: thanks.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>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

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

And obviously I replaced the email because I don’t want anyone to know what my email is.
Html:

<div class="demo2"></div>
  	<div class="content2-w3-agileits">
  	   <form action="/contact.php" method="post" class="agile-info-form">
  			<input type="email" name="Email" class="email" placeholder="Enter your email address" required="">
  			<input type="submit" value="Send it">
  			<div class="Send"> </div>
  		</form>
  	</div>

All help appreciated.

First thing I notice is you have name=“Email” on your form and email in your php code.

@Rubble I don’t know where to put name=“Email” in the php code

Input’s name attribute is written with uppercase letter while you are accessing $_POST array index with lowercase letter, named indexes are case sensitive, so change both to lowercase or uppercase.

ok for some reason it’s not emailing it to me now

i just noticed that you are using only one param in your mail function, check it out on PHP Manual: mail and learn how to use mail function.
I also suggest you to use PHP Mailer or Swift Mailer.

@marklenon95 Thanks for your help

1 Like

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