Forms +mail()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Forms +mail()

Post by Jim_Bo »

Hi,

Basically I have a form with losts of fields and check boxed, but a great number wont have any data input upon submision. When I use mail() to email me a copy of the form as well as the client I only want to email the fields that contained data along with a short description ie

$message = "name: $name";

whats the easyest way to do that?


Cheers
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Since you want to use php's mail-function, you will have to retrieve all forms data before mailing anyway. So why you can't check whether they are holding data?

djot
-
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

These two functions are used to check if data exists in a variable.
Everything gets sent, it's just that some will be empty.
It's usually a good idea to use these in form validation if you're not using a more in-depth validation method too.

http://www.php.net/empty
http://www.php.net/isset
smo
Forum Newbie
Posts: 20
Joined: Tue May 31, 2005 11:02 pm

Post by smo »

Try looping through the name and value pairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]a]806a]
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color].= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value &amp1]
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=&gt;$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= h the name and value pairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]18b806a]
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=&gt;$value)
{
if(strlen($value) &gt; 1){ // only entereairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]h the name and value pairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color:16on to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // s like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}


Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | te;$key = $value <br>";
}


Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <b
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

better use $_POST instead of $HTTP_POST_VARS for newer PHP versions...
Post Reply