email practice
Posted: Tue Oct 19, 2010 12:40 pm
Hi everyone, Right now I am trying to perfect creating a contact form and emailing the message. The two problems I am having right now is using preg_match()
for email address validation, and reporting user errors back to the user.
here is the current script I am using for the form's action
when I try to place the mail() function inside of an if statement as such
a blank page loads with the correct URL after pressing the submit button, and I am having trouble figuring out why.
I am also having trouble figuring out how to display to the user that they entered an invalid value in any of the form controls.
If anyone can tell me what to do, without really telling me how to do it, or telling me of any resources that will help with the problems I am having
I would really appreciate it. Thanks
for email address validation, and reporting user errors back to the user.
here is the current script I am using for the form's action
Code: Select all
<?php
define(EMAIL, "rmccaffe1@gmail.com");
if (!$_POST[txt_name]) {
header("Location: email_practice.php");
}
if (!$_POST[txt_email_address]) {
header("Location: email_practice.php");
}
if (!$_POST[txt_email_address]) {
header("Location: email_practice.php");
}
if (!$_POST[txta_email_message]) {
header("Location: email_practice.php");
}
$sender_name = $_POST[txt_name];
$sender_address = $_POST[txt_email_address];
$email_subject = $_POST[txt_email_message];
$email_message = $_POST[txta_email_message];
$headers[address] = $sender_address;
$result = mail(EMAIL, $email_subject, $email_message, $headers[address]);
if ($result) {
echo "Message sent successfully";
} else {
echo "Message send was unsuccessful";
}
?>Code: Select all
if (preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$^", $sender_address) {
$result = mail(EMAIL, $email_subject, $email_message, $headers[address]);
if ($result) {
echo "Message sent successfully";
} else {
echo "Message send was unsuccessful";
}
} else {
echo "Address not valid";
}
I am also having trouble figuring out how to display to the user that they entered an invalid value in any of the form controls.
If anyone can tell me what to do, without really telling me how to do it, or telling me of any resources that will help with the problems I am having
I would really appreciate it. Thanks