Hi,
Im really new to php and in my form mailer I get these errors..
Notice: Undefined index: action on line 20
Notice: Undefined index: name on line 21
Notice: Undefined index: phone on line 22
Notice: Undefined index: email on line 23
Notice: Undefined index: comments line 24
Notice: Undefined variable: ReplyToEmailAddress on line 44
Notice: Undefined variable: ReplyToEmailname on line 44
Notice: Undefined variable: sent on line 121
Here is the code
$action = $_POST["action"];
$name = $_POST["name"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$comments = $_POST["comments"];
if(strtolower($MailType) == 'html'){
$mailtypetosend = true;
} else {
$mailtypetosend = false;
}
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $email;
$mail->Host = $MailServer;
$mail->Mailer = "smtp";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $MailUsername; // SMTP username
$mail->Password = $MailPassword; // SMTP password
$mail->AddAddress($YourEmailAddress, $Yourname);
$mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML($mailtypetosend); // True for HTML, FALSE for plain text
$mail->SetLanguage("en", "language/");
//Start the page action upon submittal
if ($action == "contact" ) {
if (empty($_POST['name'])) {
$name = FALSE;
$message .= '<br>Please enter your name</br>';
} else {
$name = $_POST['name'];
}
if (empty($_POST['phone'])) {
$phone = FALSE;
$message .= '<br>Please enter a phone number to reach you at</br>';
} else {
$phone = $_POST['phone'];
}
if (empty($_POST['email'])) {
$email = FALSE;
$message .= '<br>Please enter your email address</br>';
} else {
$email = $_POST['email'];
}
if (empty($_POST['comments'])) {
$comments = FALSE;
$message .= '<br>You did not enter in a message</br>';
} else {
$comments = $_POST['comments'];
}
if($comments && $email && $phone && $name){
$mail->Subject = "Contact Us form submitted";
$mail->Body = "A contact us form has been submitted from the website\nHere are the
details:\n\n\n";
$mail->Body .= "Name: $name \n";
$mail->Body .= "Phone number: $phone\n";
$mail->Body .= "Email Address: $email\n";
$mail->Body .= "Message: $comments\n\n\n";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
$sent = 1;
}
echo "<table width=\"622\" border=\"0\" align=\"center\" class=\"table01\">
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Thank you for contacting us,
We will respond to all inquiries in the order as they are received, as soon as it is
possible.</span></td>
</tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Name: $name</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Email Address:
$email</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Phone Number:
$phone</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Message: $comments</span></td>
</tr>
<tr>
</table>";
}
}
if(isset($message)) {echo "<center><u><b>$message</span></b></u></center><br>";}
if($sent != 1){
echo "
<table width=\"424\" border=\"0\" align=\"center\" >
<form name=\"form1\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<input type=\"hidden\" name=\"action\" value=\"contact\">
<tr>
<td colspan=\"2\">Contact Form</td>
</tr>
<tr>
<td>Name</td>
<td>
<input name=\"name\" type=\"text\" value=\"$name\">
</td>
</tr>
<tr>
<td>Email Address </td>
<td><input name=\"email\" type=\"text\" value=\"$email\"></td>
</tr>
<tr>
<td>Phone Number </td>
<td><input name=\"phone\" type=\"text\" value=\"$phone\"></td>
</tr>
<tr>
<td height=\"86\">Message / Comments </td>
<td><textarea name=\"comments\" cols=\"30\" rows=\"5\" value=\"$comments\"></textarea>
</td>
</tr>
<tr>
<td height=\"20\" colspan=\"2\"><center><input type=\"submit\" name=\"Submit\"
value=\"Submit\"></center></td>
</tr>
</form>
</table>";
}
?>
Any help is greatly appreciated!