Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Im back 1

Status
Not open for further replies.

deecee

Technical User
Aug 25, 2001
1,678
US
<?php
if (array_key_exists('firstName', $_POST) || array_key_exists('lastName', $_POST) || array_key_exists('email', $_POST) ||array_key_exists('accountNumber', $_POST) || array_key_exists('question', $_POST))
{
print '<pre>';
print_r ($_POST);
}
else
{
print '<p align=&quot;center&quot;>You Have Accessed This Page Without Filling Out Our Contact Form!<br>Please <a href=&quot; Here</a> To Go To The Form</p>';
}
?>

Ok this works fine, now how would i change the

print '<pre>';
print_r ($_POST);

so I can mail this damn form out, i tried the mail() function but it didnt work

this mail function works if it is by itself and it is my original email script

<?php

$msg = &quot;Sender's Email:\t$emailbox\n\n&quot;;

$mailheaders = &quot;From: Lilliek.com\n&quot;;
$mailheaders .= &quot;Reply-to: $emailbox\n\n&quot;;

mail(&quot;DarrynC@hotmail.com&quot;, &quot;Email Address&quot;, $msg, $mailheaders);

echo &quot;<h3 align=center>Thank You</H3>&quot;;
echo &quot;<p align=center class='email'>$emailbox Has Been Added To Our Mailing List.<br>We Do Not Share Our Mailing List With Anyone</p>&quot;;
echo &quot;<p align=center class='email'><a href=' to LillieK.Com</a></p>&quot;;

?>

is there a way to combine? [soapbox]
sleep is good
 
OMFG it worked

<?php
if (array_key_exists('firstName', $_POST) || array_key_exists('lastName', $_POST) || array_key_exists('email', $_POST) ||array_key_exists('accountNumber', $_POST) || array_key_exists('question', $_POST))
{
mail(&quot;darryn@cascadecorp.com&quot;, &quot;Feedback&quot;, $firstName, &quot;From: $email&quot;);
}
else
{
print '<p align=&quot;center&quot;>You Have Accessed This Page Without Filling Out Our Contact Form!<br>Please <a href=&quot; Here</a> To Go To The Form</p>';
}
?>

how would i now combine all the fields from the form so it looks good could i just say $firstName/n$lastName

or better yet how could i format this so it looks like my second script in the first post,,,,with a subject then the input

First Name : Joe
Last Name : Blow [soapbox]
sleep is good
 
You have a lot of superfluous code in your script.

If the field $_POST['firstName'] is an input of type text, then

Code:
if (array_key_exists('firstName', $_POST) || array_key_exists('lastName', $_POST) || array_key_exists('email', $_POST) ||array_key_exists('accountNumber', $_POST) || array_key_exists('question', $_POST))

and

Code:
if (array_key_exists('firstName', $_POST))

are logically equivalent, because the field named firstName will always be submitted, so PHP will check none of the other &quot;||&quot; clauses.

I recommend that you perform the check for the presence of a single submitted field in one operation, then inside that if-block, check that each field has useful data in it. I could break your script by simply submitting a blank email address. In that case $_POST['email'] would exist but be empty. Want the best answers? Ask the best questions: TANSTAAFL!
 
so how would i combine them...would it be with 6 different if statements or would i use 1 if and 5 elseifs [soapbox]
sleep is good
 
Again, use a single-clause if-statement to check for the presence of a single form field that will always be submitted if the form is submitted.

Inside that if-statement, check that each field has valid data in it. You can use a 6-clause if-statement to check this if you want to, or use 6 nested if-statements (not as pretty to read), or use a loop to run through the field names, or a number of other ways. Probably the best way is to put this logic in a function that checks for valid input and returns a TRUE or FALSE.

Personally, I dislike detest hate loathe the elseif statement. It reduces readability, and thus maintainability, particularly when it is abused, as most so many programmers sooner or later do.
Want the best answers? Ask the best questions: TANSTAAFL!
 
sleip I took a step back as i needed to have something to show and i went with the form email.php which gets called from contact.php

<?
if (!isset($email) || !isset($firstName) || !isset($lastName) || !isset($phone) || !isset($accountNumber) || !isset($question)){
print '<a href=&quot; to the form</a>';
}
elseif (empty($email) || empty($firstName) || empty($lastName) || empty($accountNumber) || empty($question)) {
print '<p align=&quot;center&quot; class=&quot;error&quot;>Please Fill All Fields With a *</p><table width=&quot;100%&quot; height=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot; valign=&quot;middle&quot;>
<form action=&quot;email.php&quot; method=&quot;post&quot; name=&quot;contact&quot; id=&quot;contact&quot;>
<table width=&quot;500&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td colspan=&quot;4&quot;><img src=&quot;images/thebrandcollection.jpg&quot; width=&quot;400&quot; height=&quot;27&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;30&quot;>&nbsp;</td>
<td width=&quot;10&quot;>&nbsp;</td>
<td colspan=&quot;2&quot; class=&quot;respond&quot;><div align=&quot;right&quot;>We Respond To All Inquiries
Within 24 Hours<br>
<font color=&quot;#FF0000&quot;>*</font> Denotes Required Field</div></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>first name<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td width=&quot;10&quot;> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;firstName&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;firstName&quot; tabindex=&quot;1&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>last name<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;lastName&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;lastName&quot; tabindex=&quot;2&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>phone&nbsp;</div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;phone&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;phone&quot; tabindex=&quot;3&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>email<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;email&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;email&quot; tabindex=&quot;4&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>account number<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;accountNumber&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;accountNumber&quot; tabindex=&quot;5&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>question<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<textarea name=&quot;question&quot; cols=&quot;50&quot; rows=&quot;5&quot; wrap=&quot;VIRTUAL&quot; id=&quot;question&quot; class=&quot;question&quot; tabindex=&quot;6&quot;></textarea></td>
</tr>
<tr>
<td width=&quot;200&quot;><div align=&quot;right&quot;><br>
<input type=&quot;image&quot; name=&quot;Submit2&quot; value=&quot;Reset&quot; src=&quot;images/reset.gif&quot;>
</div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td></td>
<td width=&quot;280&quot;>
<div align=&quot;left&quot;> <br>
<input type=&quot;image&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; src=&quot;images/submit.gif&quot;>
</div></td>
</tr>
</table></form><SCRIPT LANGUAGE=JAVASCRIPT><!--
document.contact.firstName.focus();
//--></SCRIPT>
</table>';
}
else {
mail( &quot;darryn@cascadecorp.com&quot;, &quot;Feedback Form Results&quot;,
$firstName, $lastName, &quot;From: $email&quot; );
print 'Thank You!!!';
}
?>

i have one problem, The form has 6 total fields yet my mail function wont allow more than 2 to go through, so if i add $email after lastname then the Thank you will print but the email wont go through,

can i concact (right?) it like so

$msg = &quot;First Name:/t$firstName/n&quot;;
$msg .= &quot;Last Name:/t$lastName/n&quot;;
$msg .= &quot;Email:/t$email/n&quot;;
$msg .= &quot;Phon Number:/t$phone/n&quot;;
$msg .= &quot;Account Number:/t$account/n&quot;;
$msg .= &quot;Question:/t$question/n&quot;;

and if i can where would this go in the script? [soapbox]
sleep is good
 
so where would i put that in my script...would it go right above mail() [soapbox]
sleep is good
 
thanks i got it working [soapbox]
sleep is good
 
Sleip thanks a lot for al lyour help, I finally have my first script working and here it is

<?
if (!isset($email) || !isset($firstName) || !isset($lastName) || !isset($phone) || !isset($accountNumber) || !isset($question)){
header(&quot;Location: }
elseif (empty($email) || empty($firstName) || empty($lastName) || empty($accountNumber) || empty($question)) {
print '<p align=&quot;center&quot; class=&quot;error&quot;>Please Fill All Fields With a *</p><table width=&quot;100%&quot; height=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot; valign=&quot;middle&quot;>
<form action=&quot;email.php&quot; method=&quot;post&quot; name=&quot;contact&quot; id=&quot;contact&quot;>
<table width=&quot;500&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td colspan=&quot;4&quot;><img src=&quot;images/thebrandcollection.jpg&quot; width=&quot;400&quot; height=&quot;27&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;30&quot;>&nbsp;</td>
<td width=&quot;10&quot;>&nbsp;</td>
<td colspan=&quot;2&quot; class=&quot;respond&quot;><div align=&quot;right&quot;>We Respond To All Inquiries
Within 24 Hours<br>
<font color=&quot;#FF0000&quot;>*</font> Denotes Required Field</div></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>first name<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td width=&quot;10&quot;> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;firstName&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;firstName&quot; tabindex=&quot;1&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>last name<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;lastName&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;lastName&quot; tabindex=&quot;2&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>phone&nbsp;</div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;phone&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;phone&quot; tabindex=&quot;3&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>email<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;email&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;email&quot; tabindex=&quot;4&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>account number<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<input name=&quot;accountNumber&quot; type=&quot;text&quot; class=&quot;text&quot; id=&quot;accountNumber&quot; tabindex=&quot;5&quot;></td>
</tr>
<tr>
<td width=&quot;200&quot; height=&quot;40&quot; class=&quot;left&quot;> <div align=&quot;right&quot;>question<font color=&quot;#FF0000&quot;>*</font></div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td> <a href=&quot;390&quot;> </a></td>
<td width=&quot;280&quot;>
<textarea name=&quot;question&quot; cols=&quot;50&quot; rows=&quot;5&quot; wrap=&quot;VIRTUAL&quot; id=&quot;question&quot; class=&quot;question&quot; tabindex=&quot;6&quot;></textarea></td>
</tr>
<tr>
<td width=&quot;200&quot;><div align=&quot;right&quot;><br>
<input type=&quot;image&quot; name=&quot;Submit2&quot; value=&quot;Reset&quot; src=&quot;images/reset.gif&quot;>
</div></td>
<td width=&quot;10&quot; class=&quot;mid&quot;>&nbsp;</td>
<td></td>
<td width=&quot;280&quot;>
<div align=&quot;left&quot;> <br>
<input type=&quot;image&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; src=&quot;images/submit.gif&quot;>
</div></td>
</tr>
</table></form><SCRIPT LANGUAGE=JAVASCRIPT><!--
document.contact.firstName.focus();
//--></SCRIPT>
</table>';
}

else {

$msg = &quot;First Name:\t$firstName\n&quot;;
$msg .= &quot;Last Name:\t$lastName\n&quot;;
$msg .= &quot;Email:\t$email\n&quot;;
$msg .= &quot;Phone Number:\t$phone\n&quot;;
$msg .= &quot;Account Number:\t$accountNumber\n&quot;;
$msg .= &quot;Question:\t$question\n&quot;;

mail( &quot;darryn@cascadecorp.com&quot;, &quot;Feedback Form Results&quot;,
$msg, &quot;From: $email&quot; );
print '<p align=&quot;center&quot;>Thank You!!!<br>We Will Respond Within 24 Hours To Your Inquiry<br><a href=&quot;javascript:window.close()&quot;>Close Widnow</a>';
}
?>

if anyone wants to use it or if anyone can make it more compact or anything please feel free

I would never have guessd Id put so much work into an email script...but it has taught me a lot about variables [soapbox]
sleep is good
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top