This is how I'd do it:
The code below is the file that you specify in the "action='php file goes here'" bit.
PHP Code:
<?php
/* Step 1 - Check to see whether the user has submitted the form */
if(isset($_POST['submit'])) {
/* Step 2 - Check that the user has input something for their email */
// Using $email so it's easier to write
// The trim() function takes off any whitespace from the string
$email = trim($_POST['email']);
if(!empty($email)) {
/* Step 3 - Email isn't empty, send email */
// The email address to send to
$to = 'mailinglist@onlyjoe.co.uk';
// Message subject
$subj = 'ADD TO ONLYJOE MAILING LIST';
// Message content
$msg = $email . ' would like to be added to your mailing list.';
$headers = "From: Mailing List <mailing@onljoe.com>";
/* Step 4 - Send the email */
if(mail($to, $subj, $msg, $headers)) {
/* Redirect to success page if mail sent */
header('Location: success.html');
} else {
/* Redirect to a different page or do something else if it fails */
header('Location: error.html');
}
}
}
?>
Please not: This does not do any kind of email validation, this is more of an example of the process of sending the email. You should be able to find an email validation function with google, or I can post one if you don't have any luck.
Hope this helps you out.
Bookmarks