Jump to content


mail ()

  • Please log in to reply
2 replies to this topic

#1 aebstract

  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 07 June 2006 - 03:39 PM

I have a contact form that when fully filled out returns an "Error:" message at top of my forum, though has no errors in it. I have it set up so that if there is an error, it says "Error:" then it will list the various errors in the form. When the entire form is filled out correctly, it says error without any errors listed! Here is my script, and a link to the form:

[a href=\"http://carbenco.com/index.php?menu=contact\" target=\"_blank\"]http://carbenco.com/index.php?menu=contact[/a]

header("Cache-control: private"); 

if(isset($sent)) {
$content2 .= 'Your message has been sent.';

if(!isset($sent)) {

if (isset ($_POST['submit'])) {
$problem = FALSE;

if ($problem = TRUE) {
$content2 .= 'Errors:<br />';

$_POST['firstname'] = strip_tags($_POST['firstname']);
$_POST['lastname'] = strip_tags($_POST['lastname']);

if (empty ($_POST['firstname'])) {
$problem = TRUE;
$content2 .= 'Your first name is required<br />';

if (empty ($_POST['lastname'])) {
$problem = TRUE;
$content2 .= 'Your last name is required.<br />';

if (empty ($_POST['email1'])) {
$problem = TRUE;
$content2 .= 'Email Address is a required field.<br />';
}elseif (!preg_match("/.*@.*..*/", $_POST['email1']) OR preg_match("/(<|>)/", $_POST['email1']))
$problem = TRUE;
$content2 .= 'The email address you chose was incorrect.<br />';

if (empty ($_POST['subject'])) {
$problem = TRUE;
$content2 .= 'You are required to enter a subject.<br />';

if (empty ($_POST['body'])) {
$problem = TRUE;
$content2 .= 'You are required to submit a message.<br />';

if (!$problem) {

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email1'];
$body = $_POST['body'];
$subject = $_POST['subject'];

$sendmail = "$firstname $lastname


$sendmail2 = "Hi $firstname $lastname,
This is an automatic message sent to confirm that your following message has been sent in to carbenco:


mail ('aebstract@gmail.com', 'Contact: Carbenco', $sendmail, 'From: aebstract@gmail.com');
mail ('$email', 'Contact: Carbenco', $sendmail2, 'From: $email');

header ("Location: index.php?menu=contact&sent");

} else {

$content2 .= '<form action="index.php?menu=contact" method="post">

Contact Form<br /><br />

First Name: <br /><input type="text" class="textfield" name="firstname" maxlength="20" size="20" value="' . $_POST['firstname'] . '" /><br />
Last Name: <br /><input type="text" class="textfield" name="lastname" maxlength="20" size="20" value="' . $_POST['lastname'] . '" /><br />
Email Address: <br /><input type="text" maxlength="32" class="textfield" name="email1" size="20" value="' . $_POST['email1'] . '" /><br /><br />

Subject: <br /><input type="text" class="textfield" name="subject" maxlength="20" size="20" value="' . $_POST['subject'] . '" /><br />
Message: <br /><textarea name="body" rows="5" cols="40" class="textfieldmsg"></textarea><br /><br />

<input type="submit" name="submit" value="Send" class="textfield" /></form>';




There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.

#2 redarrow

  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 June 2006 - 04:13 PM

try adding these on false and true " ";

Wish i new all about php DAM i will have to learn

#3 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 June 2006 - 04:17 PM

The conditional operator that tests for equality is "==", not "=" which is the assignment operator.

Your code:
<?php if ($problem = TRUE) ?>
says ... assign the value TRUE to $problem. Since this succeeds, the "if" suceeds.

Change your code to
<?php if ($problem === TRUE) ?>
which will only succeed if the value of $problem is the boolean TRUE.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users