etsnyman
etsnyman

Reputation: 275

PHP and HTML submit form does not work

I have a simple form for users to sign up to e-mail updates. The HTML code on the page is as follows:

<form id='send.php' method='post'>
    <input type="email" name="emailaddress" placeholder="Your e-mail address"/>
    <input type="submit" name="submit" value="Submit">
</form>

The contents of send.php is as follows:

<?php

if($_POST["submit"]) {
    $recipient="[email protected]";
    $subject="Email address for updates";
    $sender=$_POST["emailaddress"];
    $senderEmail=$_POST["emailaddress"];
    $message=$_POST["emailaddress"];

    $mailBody="$message";

    mail($recipient, $subject, $mailBody,"From: $sender");
}

?>

If I test this, it does not work. The mailbox where these emails should be sent works fine and there are no emails in the spam folder, so I don't know what is wrong.

I am indeed a beginner with HTML and PHP.

Thanks for any help.

Upvotes: 2

Views: 90

Answers (1)

Humphrey
Humphrey

Reputation: 2817

I did not look much on your php but I sported some mistakes on the html code so First change this

<form id='send.php' method='post'>
    <input type="email" name="emailaddress" placeholder="Your e-mail address"/>
    <input type="submit" name="submit" value="Submit">
</form>

 To


<form id ="myform" action="send.php" method="post">
    <input type="email" name="emailaddress" placeholder="Your e-mail address"/>
    <input type="submit" name="submit" value="Submit">
</form>

Upvotes: 3

Related Questions