To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
After virtually, bending over backwards, I managed to FINALLY got the SMTP e-mail making it possible to actually receive the data entered by viewers in my Contactform.
Sadly, however, I was only receiving the "message" itself & NOT the "title", "first_name", "last_name", "contact_no.", etc.
I realised that I didn't include other field WITHIN php's "mail" function & hence wasn't gettting this on my e-mail (after user submits the form).
I've now added "additional parameters" (if I'm right), so as to receive all the required fields. Firstly, I'm unsure if what I've added is right or wrong & secondly, I'm getting some "syntax" error.
I think that you should asign your mail info to variables, it is hard to tell what is going on in that message. Then your mail command should look like this kinda:
// Create empty ERROR variables
$error = ""; // for fields left BLANK
$errorflag = ""; // for fields with INVALID data entered
// Check for field/fields that is/are left BLANK
if (($first_name == "") || ($last_name == "") || ($email == "") || ($phone == "") || ($message == "")) {
$error = "<span class='colorTextBlue'>Please fill in all fields!</span>";
}
else {
// Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
if (ctype_alpha($first_name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid First Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag= "first_name";
}
// Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (ctype_alpha($last_name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Last Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag="last_name";
}
// Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if ((strpos($email, "@") == FALSE)||
(strpos($email, ".") == FALSE) ||
(strpos($email, " ") != FALSE)) {
$error = "<span class='colorTextBlue'>Please enter a valid E-mail</span>";
$errorflag="email";
}
// Validate Contact No. (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (is_numeric($phone) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Contact No. <span class='italic'>(must contain numbers only)</span></span>";
$errorflag="phone";
}
}
// Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
if ($error != "") { echo "<br/> <b><span class='colorTextRed'>Error Occured: </b>" . $error."</span>" ; }
// If there's an error along with displaying the list of flagged error/errors
// If there's NO error at all, along with displaying the filled fields
else if (mail($to, $subject, $message, $headers));
{
echo "<p><span class='colorTextBlue'>E-mail sent successfully</span></p>";
echo "<p>Thanks for your comment and time. We will be in touch with you shortly, if required. Following are the details you filled in.<br/><br/>";
echo "<b>Nature of Inquiry:</b> ". $inquiry . "<br/>";
echo "<b>Title:</b> ". $title . "<br/>";
echo "<b>First Name:</b> ". $first_name . "<br/>";
echo "<b>Last Name:</b> ". $last_name . "<br/>";
echo "<b>E-mail:</b> ". $email . "<br/>";
echo "<b>Contact No.:</b> ". $phone . "<br/>";
echo "<b>Message:</b> ". $message . "<br/>";
echo "<b>Reply:</b> ". $reply . "<br/>";
echo "<b>Contact Method:</b> ". $contact . "<br/></p>";
}
else if {
$error = "<span class='colorTextRed'> E-mail NOT sent</span>";
}
}
It is actually pretty simple. This is the line causing the error:
PHP Code:
else if {
$error = "<span class='colorTextRed'> E-mail NOT sent</span>";
}
It is only seeing the else, because you don't have any conditions on the if. You either have to change it to just an else statement, or add some conditions to the if. Judging by your code I am guessing you want this to just be an else statement.
It is actually pretty simple. This is the line causing the error:
PHP Code:
else if {
$error = "<span class='colorTextRed'> E-mail NOT sent</span>";
}
It is only seeing the else, because you don't have any conditions on the if. You either have to change it to just an else statement, or add some conditions to the if. Judging by your code I am guessing you want this to just be an else statement.
I did think of that & tried changing "else if" to just "else" but to all in vain, I'm afraid. Its still showing the errors, I fear.
I've updated my code with comments all over it, making it easier to read now:
// If the form has been posted, analyse it:
if ($_POST) { // CURLY BRACKET (Open): After Clicking Submit
foreach ($_POST as $field => $value) {
$value = trim($value);
}
// Create empty ERROR variables
$error = ""; // for fields left BLANK
$errorflag = ""; // for fields with INVALID data entered
// Check for field/fields that is/are left BLANK
if (($first_name == "") || ($last_name == "") || ($email == "") || ($phone == "") || ($message == "")) { // CURLY BRACKET (Open): For Validating if fields are left blank
$error = "<span class='colorTextBlue'>Please fill in all fields!</span>";
} // CURLY BRACKET (Close): For Validating if fields are left blank
else { // CURLY BRACKET (Open): Form Validation
// Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
if (ctype_alpha($first_name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid First Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag= "first_name";
}
// Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (ctype_alpha($last_name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Last Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag="last_name";
}
// Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if ((strpos($email, "@") == FALSE)||
(strpos($email, ".") == FALSE) ||
(strpos($email, " ") != FALSE)) {
$error = "<span class='colorTextBlue'>Please enter a valid E-mail</span>";
$errorflag="email";
}
// Validate Contact No. (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (is_numeric($phone) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Contact No. <span class='italic'>(must contain numbers only)</span></span>";
$errorflag="phone";
}
} // CURLY BRACKET (Close): Form Validation
// Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
// If there's an error along with displaying the list of flagged error/errors
if ($error != "") { // CURLY BRACKET (Open): For Error
echo "<br/> <b><span class='colorTextRed'>Error Occured: </b>" . $error."</span>" ;
} // CURLY BRACKET (Close): For Error
// If there's NO error at all, along with displaying the filled fields
else if (mail($to, $subject, $message, $headers));
{
echo "<p><span class='colorTextBlue'>E-mail sent successfully</span></p>";
echo "<p>Thanks for your comment and time. We will be in touch with you shortly, if required. Following are the details you filled in.<br/><br/>";
echo "<b>Nature of Inquiry:</b> ". $inquiry . "<br/>";
echo "<b>Title:</b> ". $title . "<br/>";
echo "<b>First Name:</b> ". $first_name . "<br/>";
echo "<b>Last Name:</b> ". $last_name . "<br/>";
echo "<b>E-mail:</b> ". $email . "<br/>";
echo "<b>Contact No.:</b> ". $phone . "<br/>";
echo "<b>Message:</b> ". $message . "<br/>";
echo "<b>Reply:</b> ". $reply . "<br/>";
echo "<b>Contact Method:</b> ". $contact . "<br/></p>";
}
else {
$error = "<span class='colorTextRed'> E-mail NOT sent</span>";
}
} // CURLY BRACKET (Close): After Clicking Submit
// Displays the Empty variables i.e. when the ContactForm appears completely blank for the VERY FIRST time with all blank fields
else {
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,479
PHP Code:
else if (mail($to, $subject, $message, $headers));
If you dropped the semicolon on the end of that line PHP won't interpret it as the end of the statement "if mail() succeeds, do nothing".
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Last edited by Weedpacket; 07-08-2006 at 08:30 AM.
You will have problems with your $error and $errorflag variable if there is more than one error and the only error that will show is the very last one and the same thing with the $errorflag.
After the first error you need to concatenate the $error and $errorflag using $error .= and $errorflag .= you might want to include a <br /> at the end of each $error and $errorflag also so when printing them they are not all running together.