Hi Im trying to build a simple sign up form one where a person enters their email and submits.
This input is then emailed to the owner of the site, I thought the code below would work however it isnt?
Html code:
<form id="signup-form" method="post" action="send.php">
<input type="text" name="email" id="email" placeholder="Email Address" />
<input type="submit" value="Sign Up" />
</form>
php script:
<?php
// Change this to YOUR address
$recipient = 'email@address.co.uk';
$email = $_POST['email'];
?>
Anyone know why?
Your PHP code as it is only stores two variables, and doesn't actually do anything with them. For the built-in PHP function for sending emails, see: http://php.net/manual/en/function.mail.php
Something along the lines of:
mail($recipient, 'Email Subject', $_POST['email']);
would work, assuming the inputted data is validated correctly and an email has in fact been submitted.
UPDATE:
This file works fine and sends an email based on the behaviour you have described - running on both a local and hosted (1and1) server. Apologies for not being able to provide a solution to your problem.
<?php
$recipient = 'email@server.domain';
if (isset($_POST['email'])) {
mail($recipient, 'Email Subject', $_POST['email']);
}
?>
<form id="signup-form" method="post" action="this_file.php">
<input type="text" name="email" id="email" placeholder="Email Address" />
<input type="submit" value="Sign Up" />
</form>