/////////////////////////////////////////////Task12 /////////////////////////////////////////
$showForm = True;
//Validate that an email and Message have been filled in.
if (isset($_POST['emailADD']) && isset($_POST['Message'])){
$EmAdd = $_POST['emailADD'];
$EmMsg = $_POST['Message'];
if (!$EmAdd == null && !$EmMsg == null){
//Validate that the email address is in the correct format.
if(preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/',$EmAdd)) {
$showForm = False;
//Check if a subject header is filled in.
if (isset($_POST['emailADD'])){
$EmSub = $_POST['emailSubj'];
}
else
{
$EmSub = "Send From Task 12 with no Subject.";
}
//Send Email
mail($EmAdd, $EmSub, $EmMsg, "From:41543777@mylife.unisa.ac.za");
//Email response
echo "Thank you for contacting us!";
}
else
{
echo 'Please enter a valid email address before sending.
';
}
}
else
{
//Prompt the user for a email address.
if ($EmAdd == null){
echo 'Please enter an email address before sending.
';
}
//Prompt the user for a message.
if ($EmMsg == null){
echo 'Please enter a message before sending.
';
}
}
}
function Show_SendForm(){
?>