473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP send mail null field questions

164 100+
Ok, I will be the first to admit I am not too savvy with PHP. That being said, I was hoping for some quick help, I dont think it is too difficult, but I cant seem to come up with search results to find my answer.

My html is posting just fine to the php script, it emails, and all is well except for one thing. I have fields in the form that do not need to be filled out, and there are about 40 fields. When it gets mailed to me and if they dont fill in lets say, 30 of the 40+ fields, the entire thing gets emailed to me with no info put in those blank spots but it still has its labled that I provided it so it looks like:

Addreess:
Phone:

With 40+ of these its gets kind of hard to find the information they provided that I need, and I am worried Ill skip over something.

So the way I have it setup is just not working for me and I was wondering if there is something relatively simple I could put in the PHP script for (if the field is blank display nothing) I dont know if this will work with how I have it setup (its pretty basic)

But I have provided a SLIMMED down portion of the code that should answer any questions one may have about it.

So thank you for any advice you can give! Have a great day.. or night depending on where your at!

[PHP]<?php
$FirstName = $_REQUEST['FirstName'];
$LastName = $_REQUEST['LastName'];
$City = $_REQUEST['City'];
$State = $_REQUEST['State'];
$Zip = $_REQUEST['Zip'];
$HomePhone = $_REQUEST['HomePhone'];
$CellPhone = $_REQUEST['CellPhone'];
$Email = $_REQUEST{'Email'} ;
$Comments = $_REQUEST{'Comments'} ;

mail( "mbates@tblrock.com,", "Table Rock Restaurants Form Submission",
"First Name: $FirstName\n
Last Name: $LastName\n
City: $City\n
State: $State\n
Zip: $Zip\n
Home Phone: $HomePhone\n
Cell Phone: $CellPhone\n
Email Address: $Email\n
Comments from $FirstName $LastName : $Comments",


"From: user@website.com" );
header( "Location: http://www.website.com" );
?>[/PHP]
Apr 4 '08 #1
8 2645
aktar
105 100+
[PHP]$message = NULL;

foreach ($_REQUEST as $field_name => $value){

if (!empty($value)) $message =. "$field_name = $value<br />\n\r";
}

$to = "mbates@tblrock.com";
$subject = "Table Rock Restaurants Form Submission";
$header = "From: user@website.com";

mail($to ,$subject, $message, $header);
[/PHP]
Apr 4 '08 #2
mbatestblrock
164 100+
[PHP]$message = NULL;

foreach ($_REQUEST as $field_name => $value){

if (!empty($value)) $message =. "$field_name = $value<br />\n\r";
}

$to = "mbates@tblrock.com";
$subject = "Table Rock Restaurants Form Submission";
$header = "From: user@website.com";

mail($to ,$subject, $message, $header);
[/PHP]
Great I am going to try this out on monday, I will post back with how she goes! Thanks a ton!
Apr 5 '08 #3
mbatestblrock
164 100+
Great I am going to try this out on monday, I will post back with how she goes! Thanks a ton!

Okay, So is that script supposed to work JUST like that. I changed it to that and I get nothing when the form is submitted. It takes me to the sendmail.php page and it is just blank, and I do not receive the email.

Looking at the script it seems like it should work without any tweaking or without defining any of the form variables??

Again.. me and php dont get along. If I need to tailor this script more I would love to hear what I need to do. Ill be messing it with it until then!

THANKS!
Apr 7 '08 #4
ronverdonk
4,258 Expert 4TB
Again.. me and php dont get along. If I need to tailor this script more I would love to hear what I need to do
We are not in the habit of writing someone else's PHP scripts.

My advice to you is: follow some PHP tutorials. do some PHP practicums, then adapt your script and, if you still have problems, come back here.

Ronald
Apr 7 '08 #5
mbatestblrock
164 100+
We are not in the habit of writing someone else's PHP scripts.

My advice to you is: follow some PHP tutorials. do some PHP practicums, then adapt your script and, if you still have problems, come back here.

Ronald
Yes I know, I am not asking you to write my script. my whole script is quite lengthy, I trimmed the entire thing down just to get some advice. I got it up and running from following a tutorial. And from searching around I cannot figure out how to adapt my script to make it do the null field thing I want it to. My search results are just coming back with stuff that isnt right at all. So my apologies extend to those who feel I am being a prick and not even attempting to try and solve it by myself.. because thats not the case.
Apr 7 '08 #6
aktar
105 100+
Hi Mbates,


if you are going to have the form processor in the same page as the form itself, then you must tell php to try to process the form ONLY if certain conditions are met.

In the example below our condition will be : if form element "submit" exists

[PHP]<?php

if (isset($_REQUEST['submit'])){


$message = NULL;

foreach ($_REQUEST as $field_name => $value){

if (!empty($value)) $message =. "$field_name = $value<br />\n\r";
}

$to = "mbates@tblrock.com";
$subject = "Table Rock Restaurants Form Submission";
$header = "From: user@website.com";

mail($to ,$subject, $message, $header);

header("your_thank_you_page.html");
}
?>

<form id="form1" name="form1" method="post" action="">
<input type="text" name="textfield" id="textfield" />
<input type="text" name="textfield2" id="textfield2" />
<input type="text" name="textfield3" id="textfield3" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>[/PHP]

If the condition is not met then PHP will ignore the php bit and form will be displayed. But if the condition is met then the user will be re-directed to a thank you page.
Apr 7 '08 #7
Atli
5,058 Expert 4TB
Hi.

Just a thought...

In this case, using the $_REQUEST array is a bad idea.
You are using the data rather blindly here. Suppose I were to add this to the URL:
Expand|Select|Wrap|Line Numbers
  1. ?j=<script>location.href='www.example.com/downloadEbilViruses.html;</script>
  2.  
I cud have you re-directed just about anywhere :)

Use the $_POST array instead. That way people will actually have to do some work to send you viruses ;)

Running the input through a few cleanup functions wouldn't be a bad idea either.
The htmlentities function for example.
Apr 7 '08 #8
TheServant
1,168 Expert 1GB
Here's how I would do it:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Checks if this is the right form (I suggest only have required field here, so say FirstName, LastName, Email and Comments):
  3. if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['FirstName']) && isset($_POST['LastName']) && isset($_POST['Email']) && isset($_POST['Comments']) )
  4. {
  5.  
  6. if ( $_POST['FirstName'] == "" || $_POST['LastName'] == "" || $_POST['Email']] == "" || $_POST['Comments'] == "" )
  7. {
  8. echo ('You have not entered the required information');
  9. } else {
  10.  
  11. $FirstName = $_POST['FirstName'];
  12. $LastName = $_POST['LastName'];
  13. $City = $_POST['City'];
  14. $State = $_POST['State'];
  15. $Zip = $_POST['Zip'];
  16. $HomePhone = $_POST['HomePhone'];
  17. $CellPhone = $_POST['CellPhone'];
  18. $Email = $_POST['Email'] ;   //You know you had { instead of [ ?
  19. $Comments = $_POST['Comments'] ;
  20.  
  21. //Now for the message, you only need to check the ones which are optional
  22. $message = "
  23. First Name: $FirstName\n
  24. Last Name: $LastName\n
  25. if ($City != NULL) {City: $City\n}
  26. if ($State != NULL) {State: $State\n}
  27. if ($Zip != NULL) {Zip: $Zip\n}
  28. if ($HomePhone != NULL) {Home Phone: $HomePhone\n}
  29. if ($CellPhone != NULL) {Cell Phone: $CellPhone\n}
  30. Email Address: $Email\n
  31. Comments from $FirstName $LastName : $Comments"
  32.  
  33.  
  34. mail( "mbates@tblrock.com,", "Table Rock Restaurants Form Submission",
  35. $message,"From: user@website.com" );
  36. }
  37. header( "Location: http://www.website.com" );
  38. }
  39. ?>
Or something like that. Maybe I have made a mistake, but it should give you some more insight into what php can do.

[EDIT]Aktar's foreach loop is a better way of doing this, but mine is a longer and in some senses simpler, so you might follow it a bit better.
Apr 8 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This...
10
by: I_love_php | last post by:
What is the best way to send one email to 9000 users without them getting it in Junk mail ? Please help me with ur ideas
4
by: Devhead | last post by:
i need to present user with an Outlook mail item. the following code is a modication to the code found here(http://support.microsoft.com/?kbid=819398). However, when the line is question is...
3
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
3
by: Max | last post by:
hi I used mailmessage object to send the mail, my smtp server don't require authentication, when i try to send the mail it shows error. following is the code to send mail. Dim mymail As New...
14
by: Professor Yonce | last post by:
I have made form for E-Mail. I have entered code but the Import system does not work. It has squiggly line underneath it showing it is not communicating. It Will not build. Public Class...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
4
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
I have a web page that at the click of a button must send a bunch (1000+) emails. Each email is sent individually. I have the code working fine, using Mail Message classes and smtp and all that. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.