I have a signup form that is supposed to add a person to the DB and send them a 'you've signed up' email. I'm modifying someone else's form because I have to use some of the existing functionality of it.
I've got the form adding the person to the DB but the 'you've signed up' email isn't being sent out.
Code:
//FORM GOES HERE...
if (isset($_POST['SignUp']))
{
$EmailAddress = $_POST['Email'];
$FullName = $_POST['FullName'];
$TheAge = $_POST['Age'];
$DueDateMonth = $_POST['Month'];
$DueDateDay = $_POST['Day'];
$DueDateYear = $_POST['Year'];
$DueDate = $DueDateYear."-".$DueDateMonth."-".$DueDateDay;
$Result = mysql_query("SELECT * FROM EmailUsers WHERE EmailAddress = '".$EmailAddress."'");
if (mysql_num_rows($Result) == 0)
{
//Add the user and send intro email...
$AddResult = mysql_query("INSERT INTO EmailUsers (EmailAddress, Name, DueDate, Age) VALUES ('".$EmailAddress."', '".addslashes($FullName)."', '".$DueDate."', ".$TheAge.")");
if ($AddResult)
{
echo 'Thank you for signing up with our email alerts program. A confirmation email has been sent to: <B>'.$EmailAddress.'</B>.<br /><br />theFunkystork.com staff.';
$Subject = "Welcome to theFunkystork.com - Track Your Pregnancy";
$Header = "Return-Path: track-your-pregnancy@thefunkystork.com\r\n";
$Header .= "From: theFunkystork <track-your-pregnancy@thefunkystork.com>\r\n";
//Grab the initial email to send to people (The Welcome Message).
$Result = mysql_query("SELECT * FROM EmailAlerts WHERE Week = 0");
$Row = mysql_fetch_array($Result);
$Message = stripslashes($Row['EmailText']);
mail ($EmailAddress, $Subject, $Message, $Header);
}
else
{
//Unsuccessful - for some reason...
}
}
else
{
echo 'The email address you entered (<b>'.$EmailAddress.'</b>) already exists in our database.';
}
}
else
{
//Show signup form...
$CurrentYear = date('Y');
$NextYear = $CurrentYear + 1;
$CurrentMonth = date('m');
$CurrentDay = date('d');
?>
<form name="TrackPregForm" method="post" action="pregnancy_email_thank_you">
<table border="0" cellpadding="3">
<tr><td align="right">
Your Name:
</td><td>
<input type="text" name="FullName" />
</td></tr>
<tr><td align="right">
Your Age:
</td><td>
<input type="text" name="Age" size="5" maxlength="2" />
</td></tr>
<tr><td align="right">
Your Email Address:
</td><td>
<input type="text" name="Email" />
</td></tr>
<tr><td colspan="2" align="center">
<br />
<B>Enter Your Due Date</B>
</td></tr>
<tr><td align="right">
Month:
</td><td>
<select name="Month">
<?php
$AllMonths = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
for ($x = 0; $x < 12; $x++)
{
if (($x + 1) == ((int) $CurrentMonth))
{
if ($x < 9)
{
echo '<option value="0'.($x + 1).'" selected>'.$AllMonths[$x].'</option>';
}
else
{
echo '<option value="'.($x + 1).'" selected>'.$AllMonths[$x].'</option>';
}
}
else
{
if ($x < 9)
{
echo '<option value="0'.($x + 1).'">'.$AllMonths[$x].'</option>';
}
else
{
echo '<option value="'.($x + 1).'">'.$AllMonths[$x].'</option>';
}
}
}
?>
</select>
</td></tr>
<tr><td align="right">
Day:
</td><td>
<select name="Day">
<?php
for ($x = 1; $x < 32; $x++)
{
if ($x == ((int) $CurrentDay))
{
if ($x < 10)
{
echo '<option value="0'.$x.'" selected>'.$x.'</option>';
}
else
{
echo '<option value="'.$x.'" selected>'.$x.'</option>';
}
}
else
{
if ($x < 10)
{
echo '<option value="0'.$x.'">'.$x.'</option>';
}
else
{
echo '<option value="'.$x.'">'.$x.'</option>';
}
}
}
?>
</select>
</td></tr>
<tr><td align="right">
Year:
</td><td>
<select name="Year">
<?php
//output this year and next...
echo '<option value="'.$CurrentYear.'" selected>'.$CurrentYear.'</option>';
if ($CurrentMonth != '01' && $CurrentMonth != '02') //If it's not at least march, don't show the option for next year...
{
echo '<option value="'.$NextYear.'">'.$NextYear.'</option>';
}
?>
</select>
</td></tr>
<tr><td colspan="2" align="center">
<input type="button" value="Track Your Pregnancy" onClick="validateTrackPreg();" />
</td></tr>
</table>
<input type="hidden" name="SignUp" value="True" />
</form>
<?php
}
?>
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
//Form Validationg for Track Pregnancy...
function validateTrackPreg()
{
var isValid = false;
//Validate Name...
var theName = document.TrackPregForm.FullName.value;
var theAge = parseInt(document.TrackPregForm.Age.value);
if (theName != "")
{
isValid = true;
//Validate Age
if (!(theAge) || theAge < 18)
{
isValid = false;
alert('Please enter your age. (18 and older only).');
document.TrackPregForm.Age.focus();
}
if (isValid)
{
//Validate Email Address...
var theEmail = document.TrackPregForm.Email.value;
var atLoc = theEmail.indexOf("@", 1);
var dotLoc = theEmail.indexOf(".", atLoc + 2);
var len = theEmail.length;
if (atLoc > 0 && dotLoc > 0 && len > dotLoc + 2)
{
isValid = true;
}
else
{
isValid = false;
//alert user and set focus to email...
alert('Please enter a valid email address...');
document.TrackPregForm.Email.focus();
}
//End Validate Email Address
}
if (isValid)
{
//Validate Due Date - Only allow a date that is at least one week in the future
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
var currentDay = currentDate.getDate();
var currentYear = currentDate.getFullYear();
if (document.TrackPregForm.Year.value == currentYear)
{
//If it's this year, make sure the month & day are not in the past, and at least 1 week from today..
if (document.TrackPregForm.Month.value < currentMonth)
{
alert ('You cannot enter a due date from the past.\n\nPlease enter a due date that is at least one week from now.');
isValid = false;
document.TrackPregForm.Month.focus();
}
else if (document.TrackPregForm.Month.value == currentMonth && document.TrackPregForm.Day.value < (currentDay + 7))
{
alert('You must enter a due date that is at least one week from now.');
isValid = false;
document.TrackPregForm.Month.focus();
}
else if ((document.TrackPregForm.Month.value - currentMonth) > 10)
{
alert('You cannot enter a due date more than 10 months in the future.');
isValid = false;
document.TrackPregForm.Month.focus();
}
}
else
{
//If the due date is next year, only allow a due date that's 10 months or less in the future...
if (((document.TrackPregForm.Month.value - currentMonth) + 12) > 10)
{
alert('You cannot enter a due date more than 10 months in the future.');
isValid = false;
document.TrackPregForm.Month.focus();
}
}
if ((document.TrackPregForm.Month.value == 4 || document.TrackPregForm.Month.value == 6 || document.TrackPregForm.Month.value == 9 || document.TrackPregForm.Month.value == 11) && document.TrackPregForm.Day.value > 30)
{
alert('Please enter a valid date.');
isValid = false;
document.TrackPregForm.Month.focus();
}
else if (document.TrackPregForm.Month.value == 2 && document.TrackPregForm.Day.value > 28)
{
//Check to see if it's a leap year....
var remainder = (currentYear - 2004) % 4; //2004 was the most recent leap year.
if (remainder < 1) //It's a valid leap year.
{
//make sure day is only 29
if (document.TrackPregForm.Day.value != 29)
{
alert('Please enter a valid date.');
isValid = false;
document.TrackPregForm.Month.focus();
}
}
else
{
alert('Please enter a valid date.');
isValid = false;
document.TrackPregForm.Month.focus();
}
}
//End Validate Due Date
}
}
else
{
isValid = false;
//alert user and set focus to Name...
alert('Please enter your name.');
document.TrackPregForm.FullName.focus();
}
if (isValid)
{
//Submit Form...
document.TrackPregForm.submit();
}
}
//Form Validationg for Track Pregnancy Opt Out...
function validateOptOut()
{
isValid = true;
//Validate Email Address...
var theEmail = document.OptOutForm.Email.value;
var atLoc = theEmail.indexOf("@", 1);
var dotLoc = theEmail.indexOf(".", atLoc + 2);
var len = theEmail.length;
if (atLoc > 0 && dotLoc > 0 && len > dotLoc + 2)
{
isValid = true;
}
else
{
isValid = false;
//alert user and set focus to email...
alert('Please enter a valid email address...');
document.OptOutForm.Email.focus();
}
//End Validate Email Address
if (isValid)
{
//Submit Form...
document.OptOutForm.submit();
}
}
//-->
</script>