/    Sign up×
Community /Pin to ProfileBookmark

PHP mail form problem

hello am having problems with PHP script, i’m trying to do a feedback page for a website using the php mail function but i also want to pick up errors on the page i.e. the user is required to enter data into all fields and i’m wanting to make them a regualr expression.

my problem is i can get it to check for the errors but the form does not email the data.

i have done echo statements near the mail() function call and they print out to screen however it doesnt work.

so what i have done temporially is revert to my old code which submits the data but doesnt do error checking.

i have posted new and old data if anyone can point out my mistake it would greatly be appreicated.

code which i cant get to work does error checking my means of putting red astrirks to areas which require a response

<?
$arrErrors = array();

if (!empty($_POST[‘Submit’]))
{
$sendform = true;

//contact details
if($_POST[‘name’]==”)
$arrErrors[‘name’]= ‘*’;
if($_POST[’email’]==”)
$arrErrors[’email’]= ‘*’;
if($_POST[‘occupation’]==”)
$arrErrors[‘occupation’]= ‘*’;

//vehicle information experssions
if($_POST[‘make’]==”)
$arrErrors[‘make’]= ‘*’;
if($_POST[‘model’]==”)
$arrErrors[‘model’]= ‘*’;
if($_POST[‘year’]==”)
$arrErrors[‘year’]= ‘*’;
if($_POST[‘engine’]==”)
$arrErrors[‘engine’]= ‘*’;

//Question infromation experssions
if($_POST[‘question1’]==”)
$arrErrors[‘question1’]= ‘*’;
if($_POST[‘question2’]==”)
$arrErrors[‘question2’]= ‘*’;
if($_POST[‘question3’]==”)
$arrErrors[‘question3’]= ‘*’;
if($_POST[‘question4’]==”)
$arrErrors[‘question4’]= ‘*’;
if($_POST[‘question5’]==”)
$arrErrors[‘question5’]= ‘*’;
if($_POST[‘question6’]==”)
$arrErrors[‘question6’]= ‘*’;
if($_POST[‘question7’]==”)
$arrErrors[‘question7’]= ‘*’;

if (count($arrErrors) >= 1) {
$strError = ‘Please check the following fields with red astrik (*) and try again:’;
}
//$sendform == true;

else if($sendform==true) {
// If the error array is empty, there were no errors.
// Insert form processing here.
$headers = “From: “.$name.”<“.$email.”>nReply-website”;
//$message =”Persons Contact Details”
//Response in email message.
//contact detail information
$message =”From :$namen”;
$message .=”Email Address :$emailn”;
$message .=”Contact Details :$contact_detailsn”;
$message .=”Occupation :$occupationn”;

//vehicle information
$message .=”Make :$maken”;
$message .=”Model :$modeln”;
$message .=”Year :$yearn”;
$message .=”Engine :$enginen”;

//Question information

[COLOR=Red]took out most of the questions[/COLOR]

[COLOR=Blue]Have put in echo statement before and after the issent= mail( $recpient…………..) however still doest not work [/COLOR] ? ?

$issent = mail($recipient, $subject, $message, $headers);
echo “thankyou for your time everything has been submitted”;

}
}
?>

current code which submits everything but doenst do appropiate checking i think the reason why the code that does not submit everything may have something to do with this code below i.e the while loop

<?
$sendform = false;
if(isset($_POST[‘Submit’])){
while(list($key,$val) = each($_
POST)){
$$key = $val;
if($val!=”) $sendform = true;
}
//regular experssions
if((!eregi(“^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$”, $email))){
echo “<span class=”style17”>Invalid type email address! i.e. [email][email protected][/email] n </span>”;

//contact details
if(empty($name)){echo(“No Name Entered, please enter<br />”);}
if(empty($email)){echo(“No E-Mail Entered, please enter<br />”);}
if(empty($occupation)){echo(“No Occupation Entered, please enter<br />”);}

//vehicle information experssions

}
else if($sendform==true) {
$headers = “From: “.$name.”<“.$email.”>nReply-
//$message =”Persons Contact Details”
//Response in email message.
//contact detail information

[COLOR=Red]Note: Code has been simplified[/COLOR]

$issent = mail($recipient, $subject, $message, $headers);

if(isset($issent)) echo “<span class=”newstime”>Thank you for your time</span>”;
} else echo “<span class=”newstime”>All fields must be filled in. Unable to send form.</span>”;

}
?>

if anyone can help it would greatly be appreicated

cheers

James

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehJun 20.2005 — Hi! Put the following at the end of your script to try to track down what's going wrong:
[code=php]
echo '<pre>';
echo '<br>$arrErrors<br>';
var_dump($arrErrors);
echo '<br>$sendform<br>';
var_dump($sendform);
echo '<br>$issent<br>';
var_dump($issent);
echo '<br>$recipient<br>';
var_dump($recipient);
echo '<br>$subject<br>';
var_dump($subject);
echo '<br>$message<br>';
var_dump($message);
echo '<br>$headers<br>';
var_dump($headers);
echo '</pre>';
[/code]
×

Success!

Help @morkz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...