473,386 Members | 1,804 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,386 software developers and data experts.

Creating a simple feedback form using php

Hi all,

here my simple code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $name = $_REQUEST['name']; 
  4. $email = $_REQUEST['text']; 
  5. $comment = $_REQUEST['comment']; 
  6.  
  7. mail( "mymail@xyz.xz", "Feedback Form",
  8. $name, $comment, "From: $email" );
  9. header( "Location: http://www.megawhite.au" );
  10.  
  11. ?>
  12.  
I need to check, if ALL of the fields are filled. If yes - then go to www.megawhite.. if NOT - to some other www.

I know, that it is somehow possible with "empty" command.. :rolleyes:

Can You put me on the right way, please?

Thanx.
Nov 28 '07 #1
11 2798
Markus
6,050 Expert 4TB
Hi all,

here my simple code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $name = $_REQUEST['name']; 
  4. $email = $_REQUEST['text']; 
  5. $comment = $_REQUEST['comment']; 
  6.  
  7. mail( "mymail@xyz.xz", "Feedback Form",
  8. $name, $comment, "From: $email" );
  9. header( "Location: http://www.megawhite.au" );
  10.  
  11. ?>
  12.  
I need to check, if ALL of the fields are filled. If yes - then go to www.megawhite.. if NOT - to some other www.

I know, that it is somehow possible with "empty" command.. :rolleyes:

Can You put me on the right way, please?

Thanx.
You could use strlen()

i.e.
[php]
if((strlen($name) > 0) && (strlen($text) > 0) && strlen($comment) > 0)){
// fields aren't empty - execute relevant code
} else {
// a field is empty - execute relevant code
}
[/php]
That's just an easy and robust way of doing it :)
Nov 28 '07 #2
thanx, man :)

so, now it looks like below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. $name = $_REQUEST['name']; 
  5. $email = $_REQUEST['text']; 
  6. $comment = $_REQUEST['comment']; 
  7.  
  8. if((strlen($name) > 0) && (strlen($email) > 0) && strlen($comment) > 0)){
  9.    header ("Location: http://www.pleasefilltheform.com");
  10.  
  11. else {
  12. mail("mymail@xyz.xz", "Feedback Form",
  13. $name, $comment, "From: $email");
  14. header ("Location: http://www.thankyoupage.com");
  15. }
  16.  
  17. ?>
  18.  
but the thing is, that when i receive form results on email, in sender's field i see the mail, i indicated in my hosting options, e.g. i write in form: blabla@bla.com, but when the message arrives, i see not blabla@com., but info@mywebsite.com... ?

why is it so, and how we can change it?
Dec 1 '07 #3
ak1dnar
1,584 Expert 1GB
Your question is not that much clear to me, but check this out.
Expand|Select|Wrap|Line Numbers
  1. $to = 'your_mail@domain.com';
  2. $headers = "Reply-to: $email\n";
  3. $headers  .= 'MIME-Version: 1.0' . "\r\n";
  4. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  5. $headers .= 'From: Web Mailer <from_addreass@goes_here.com>' . "\r\n";
  6. mail($to, "Mail Subject", 'Mail Body Mail Body Mail Body', $headers);
Better to use these headers with your mail function
Dec 1 '07 #4
Markus
6,050 Expert 4TB
Your question is not that much clear to me, but check this out.
Expand|Select|Wrap|Line Numbers
  1. $to = 'your_mail@domain.com';
  2. $headers = "Reply-to: $email\n";
  3. $headers  .= 'MIME-Version: 1.0' . "\r\n";
  4. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  5. $headers .= 'From: Web Mailer <from_addreass@goes_here.com>' . "\r\n";
  6. mail($to, "Mail Subject", 'Mail Body Mail Body Mail Body', $headers);
Better to use these headers with your mail function
Also looking at your code, it would seem you had it wrong.

Doing this
[php]
if((strlen($name) > 0) && (strlen($email) > 0) && strlen($comment) > 0)){
header ("Location: http://www.pleasefilltheform.com");
} else {
mail("mymail@xyz.xz", "Feedback Form",
$name, $comment, "From: $email");
header ("Location: http://www.thankyoupage.com");
}
[/php]
would send the mail if the strlen function checks return false! i.e. sending the email if the fields havent been filled out.

Swap it around
i.e.
[php]
if(((strlen($name) > 0) && (strlen($email) > 0) && strlen($comment) > 0))){
//strlen() returns TRUE, send mail.
mail("mymail@xyz.xz", "Feedback Form",
$name, $comment, "From: $email");
header ("Location: http://www.thankyoupage.com");
} else {
// email wasnt filled out properly! Redirect.
header ("Location: http://www.pleasefilltheform.com");
}
[/php]
Dec 1 '07 #5
[php]
if(((strlen($name) > 0) && (strlen($email) > 0) && strlen($comment) > 0))){
//strlen() returns TRUE, send mail.
mail("mymail@xyz.xz", "Feedback Form",
$name, $comment, "From: $email");
header ("Location: http://www.thankyoupage.com");
} else {
// email wasnt filled out properly! Redirect.
header ("Location: http://www.pleasefilltheform.com");
}
[/php]
thanx again, now this part is clear for me :) but what about those headers from Ajaxrand? as i uderstand i should write the addresses like variables to send the mail correctly?
Dec 1 '07 #6
ak1dnar
1,584 Expert 1GB
thanx again, now this part is clear for me :) but what about those hAjaxrandrom Ajaxranduderstand i uderstand i should write the addresses like variables to send the mail correctly?
For the mail() function you can pass headers. Its only a enhancement for your script. first I thought that, you are having a problem with sending "FROM" header with the mail. Sorry If I got it on the wrong way. anyway have a look at these user comments on mail function anphpeaders in the php manual
You can set the parameters for mail(......) function as variable or directly, No matter. but for better manageability of the mail function I am always passing variables, rather than typing the values. That's It.
And also the headers, you need to learn more of them when time comes with HTML mails and mails with attachments.
Dec 1 '07 #7
Markus
6,050 Expert 4TB
Like ajax mentioned, the headers aren't completely necessary; if you just wanted to send a plain text email then you could leave them out, but if you wanted to send a html formatted email, then you would need to include these headers.

:)
Dec 2 '07 #8
i have not understood about those headers clearly - will they help to solve this "from" problem or no? :)

seems, i dont need them , as Markus said, I want just plain text results from my form.
Dec 2 '07 #9
ak1dnar
1,584 Expert 1GB
i have not understood about those headers clearly - will they help to solve this "from" problem or no? :)

seems, i dont need them , as Markus said, I want just plain text results from my form.
This "from" problem, what's wrong with your "From" header. Is it not displaying in the mail?
Dec 2 '07 #10
yes, when i receive form results on my mail, i see in "from" field, the mail, i identified as my default hosting mail (in my hosting options). this is happening, inspite of writing the mail in "email" field.
Dec 2 '07 #11
yes, when i receive form results on my mail, i see in "from" field, the mail, i identified as my default hosting mail (in my hosting options). this is happening, inspite of writing the mail in "email" field.
are there any advices you can give?
Dec 4 '07 #12

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

Similar topics

2
by: Mindful_Spirit | last post by:
I'm trying to set up a basic email feed back form like this, and was wondering about some basic configuration settings. I have used code from this website. I have it working just fine. I'm...
5
by: Vandana Rola | last post by:
Hello Everyone, I am a beginner in Javascript.I want to create fun quiz tool using javascript (no database). The feature of that tool is every question has five choices. The user needs to select...
2
by: Iain Miller | last post by:
Now this shouldn't be hard but I've been struggling on the best way as to how to do this one for a day or 3 so I thought I'd ask the assembled company..... I'm writing an application that tracks...
11
by: Paul Tremblay | last post by:
Hi, I can't seem to locate the visual C++ (pre .NET) ng. This may be slight off topic here - please point me to the correct ng if it is. Without going into much detail (and repeating myself...
1
by: Hasani \(remove nospam\) | last post by:
The way the system works is, you create a user control (ascx) that will be a template and must implement the interface IPageTemplate. You then create one or more user controls (ascx) that implement...
4
by: ianbarton | last post by:
Hello all I am trying to setup a feedback form on my webpage using some script provided by my ISP. I really don't know a lot about PHP and it's syntax etc. The feedback form only has 4...
9
by: MikeB | last post by:
Hi, I'd appreciate some help, please. I'm writing a VS2005 VB project for school and one of the requirements is that every screen should have a "Help" button. I could do it by writing a clumsy...
31
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
4
by: atiq | last post by:
I basically have a mail to form on my website. When the form is filled and submitted by the user it processes the form using the file feedback.php. What i want is a Pop up window which says "thank...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.