MOHinc
06-30-2009, 03:23 PM
Hi, I would appreciate if some of you on here can help me out. I enjoyed this web site, and the forums. I am helping to create a web site for Non Profit Group, and the web site is here http://www.missionariesofhopeinc.com/ . On the left hand side of the page I am trying to get visitors to sign up for a mailing list. I am new at PHP , and the site is hosted at GoDaddy. I was wondering if any of you can look at the code, and give me pointers and show me how it should be done. I would like the information to be sent to missionariesofhopeinc@hotmail.com , when the user submits it.
Thanks in advance, I will check back and forth during the day or days to come.
Index Code Below:
<form action="mail.php" method="POST"><b>First Name:</b><br><input
type="text" name="firstname" size=24 maxlength="24"/><br><b>Last
Name:</b><br><input type="text" name="lastname" size=24
maxlength="24"/><br><b>Email:</b><br><input type="text" name="email"
size=24 maxlength="70"/></textarea><br><input type="submit" value="Join
Mailing List">
PHP Code Below:
<?php
/* All form fields are automatically passed to the PHP script through the
array $HTTP_POST_VARS. */
$firstname = $HTTP_POST_VARS['firstname'];
$lastname = $HTTP_POST_VARS['lastname'];
$email = $HTTP_POST_VARS['email'];
/* PHP form validation: the script checks that the Email field contains a
valid email address and the Subject field isn't empty. preg_match
performs a regular expression match. It's a very powerful PHP function to
validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email =
'missionariesofhopeinc@hotmail.com')) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
/* Sends the mail and outputs the "Thank you" string if the mail is
successfully sent, or the error string otherwise. */
elseif (mail($firstname,$lastname,$email =
'missionariesofhopeinc@hotmail.com)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email =
'missionariesofhopeinc@hotmail.com</h4>";
}
?>
Thanks in advance, I will check back and forth during the day or days to come.
Index Code Below:
<form action="mail.php" method="POST"><b>First Name:</b><br><input
type="text" name="firstname" size=24 maxlength="24"/><br><b>Last
Name:</b><br><input type="text" name="lastname" size=24
maxlength="24"/><br><b>Email:</b><br><input type="text" name="email"
size=24 maxlength="70"/></textarea><br><input type="submit" value="Join
Mailing List">
PHP Code Below:
<?php
/* All form fields are automatically passed to the PHP script through the
array $HTTP_POST_VARS. */
$firstname = $HTTP_POST_VARS['firstname'];
$lastname = $HTTP_POST_VARS['lastname'];
$email = $HTTP_POST_VARS['email'];
/* PHP form validation: the script checks that the Email field contains a
valid email address and the Subject field isn't empty. preg_match
performs a regular expression match. It's a very powerful PHP function to
validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email =
'missionariesofhopeinc@hotmail.com')) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
/* Sends the mail and outputs the "Thank you" string if the mail is
successfully sent, or the error string otherwise. */
elseif (mail($firstname,$lastname,$email =
'missionariesofhopeinc@hotmail.com)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email =
'missionariesofhopeinc@hotmail.com</h4>";
}
?>