Mail Form

Hey All~

I am a n00b and looking for some help, please. I am using the Kirupa PHP Mailer, but my server is posting errors on “submit”. Here’s what i have so far:

My HTML form is formatted thusly:

<form method=“POST” action=“mailer.php” style=“background: url(images/portbkg3.gif) no-repeat; padding: 30px; border: 1px;”><br />
Name:
<input type=“text” name=“name” size=“29”><br>

E-Mail:
<input type=“text” name=“email” size=“29”><br>
<br>
<strong>First visit to loydster.com?</strong><br /><input type=“radio” value=“yes” name=“radio”> YES    <input type=“radio” value=“no” name=“radio”> NO
<br><br />
<strong>What is the nature of your query?</strong><br />
<input type=“checkbox” name=“check[]” value=“opportunity”> Opportunity <input type=“checkbox” name=“check[]” value=“quote”> Quote
<input type=“checkbox” name=“check[]” value=“comment”> Comment<br>
<br>
<select size=“1” name=“drop_down”>
<option>Please select your area of interest:</option>
<option>Website Design</option>
<option>UI Design</option>
<option>Graphic Design</option>
<option>Technical Writing or Quality Analysis</option>
</select><br>
<br>
<strong>Message:</strong><br>
<textarea rows=“7” name=“message” cols=“30”></textarea><br>
<br>
     <input type=“submit” value=“Submit” name=“submit”><br /><br />
</form>

The form resides on my server www.loydster.com and the SERVER PHP FILE contains this information:

<?php
if(isset($_POST[‘submit’])) {
$to = “[email protected]”;
$subject = “Inquiry or Comment”;
$name_field = $_POST[‘name’];
$email_field = $_POST[‘email’];
$message = $_POST[‘message’];
$option = $_POST[‘radio’];
$dropdown = $_POST[‘drop_down’];
foreach($_POST[‘check’] as $value) {
$check_msg .= "Checked: $value
";
}

$body = "From: $name_field
E-Mail: $email_field
$check_msg Option: $option
Drop-Down: $dropdown
Message:
$message
";
echo “Thank you for contacting $to!”;
mail($to, $subject, $body);

} else {
echo “Error on email posting.”;
}
?>

When I post from my Web page, I get the following ERROR MESSAGE:

Notice: Undefined variable: check_msg in d:\Customers\user1220675\www\mailer.php on line 13
Thank you for contacting [email protected]!
Warning: mail(): SMTP server response: 553 5.3.0 <[email protected]>… DISCARD Spam Relay in d:\Customers\user1220675\www\mailer.php on line 19

The code looks good (to me) and I am wondering if this is a “permissions” issue? Any help is greatly appreciated. And thanks in advance.:pac:

See here (http://www.larrykooper.com/?p=11) for more info about the mail error. The notice you get about the $check_msg var is issued because you are doing concatenation on the variable but it does not exist. Try to declare it before the foreach (ie. $check_msg=’’; )

Thank you Angus. I viewed the Larry Kooper site and added some code into the PHP. This is what I have now with the new error message:

<?php
ini_set(“sendmail_from”, “[email protected]”);
if(isset($_POST[‘submit’])) {
$to = “[email protected]”;
$subject = “Inquiry or Comment”;
$name_field = $_POST[‘name’];
$email_field = $_POST[‘email’];
$message = $_POST[‘message’];
$option = $_POST[‘radio’];
$dropdown = $_POST[‘drop_down’];
foreach($_POST[‘check’] as $value) {
$check_msg .= “Checked: $value
”;
}

$body = “From: $name_field
E-Mail: $email_field
$check_msg Option: $option
Drop-Down: $dropdown
Message:
$message
”;
echo “Thank you for contacting $to!”;
mail($to, $subject, $body);

} else {
echo “Error on email posting.”;
}
?>

Error Message:
ERROR MESSAGE
Notice: Undefined variable: check_msg in d:\Customers\user1220675\www\mailer.php on line 13
Thank you for contacting [email protected]!if(isset($_POST[‘submit’])) {19

as the previous poster said, the problem is:

$check_msg .= “Checked: $value
”;

You don’t declare it before you use it…

if(isset($_POST[‘submit’])) {
$check_msg =’’;
$to = "[email protected]";
$subject = “Inquiry or Comment”;
etc…

would fix that error

but that script is pretty bare, you should get one with a minimum of security checking so that your form doesn’t become a spammer’s heaven…