Jump to content
Updating IPB tonight Read more... ×


This topic is now archived and is closed to further replies.


mail ()

Recommended Posts

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>';





Share this post

Link to post
Share on other sites
The conditional operator that tests for equality is "==", not "=" which is the assignment operator.

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

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


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.