473,788 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a simple feedback form using php

6 New Member
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 2834
Markus
6,050 Recognized Expert Expert
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($nam e) > 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
coldrex
6 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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($nam e) > 0) && (strlen($email) > 0) && strlen($comment ) > 0)){
header ("Location: http://www.pleasefillt heform.com");
} else {
mail("mymail@xy z.xz", "Feedback Form",
$name, $comment, "From: $email");
header ("Location: http://www.thankyoupag e.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($na me) > 0) && (strlen($email) > 0) && strlen($comment ) > 0))){
//strlen() returns TRUE, send mail.
mail("mymail@xy z.xz", "Feedback Form",
$name, $comment, "From: $email");
header ("Location: http://www.thankyoupag e.com");
} else {
// email wasnt filled out properly! Redirect.
header ("Location: http://www.pleasefillt heform.com");
}
[/php]
Dec 1 '07 #5
coldrex
6 New Member
[php]
if(((strlen($na me) > 0) && (strlen($email) > 0) && strlen($comment ) > 0))){
//strlen() returns TRUE, send mail.
mail("mymail@xy z.xz", "Feedback Form",
$name, $comment, "From: $email");
header ("Location: http://www.thankyoupag e.com");
} else {
// email wasnt filled out properly! Redirect.
header ("Location: http://www.pleasefillt heform.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 Recognized Expert Top Contributor
thanx again, now this part is clear for me :) but what about those hAjaxrandrom Ajaxrandudersta nd 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 Recognized Expert Expert
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
coldrex
6 New Member
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 Recognized Expert Top Contributor
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

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

Similar topics

2
5224
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 running IIS on my home machine. My problem is that I need to upload this stuff to a webhosting place and register a domain and I'm not sure what to put as the smtp mail server value
5
5758
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 three best choices. If they do, a message window pops up which says good choices or something and take them to next question. If they don't choose all of the best choices they get another message like try again but these are not the best choices...
2
5972
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 a group of Sales people, the customers they deal with and the business they transact with them. I've got my head around all the tables & some of the basic Query structures OK and am beginning to delve into creating the forms I need to be able...
11
2978
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 several times), I am using Visual C++ 6.0 to develop applications - *instead* of .Net. I am using the MFC to create my GUI components. I am particularly interested in doing the ff with my GUI:
1
1778
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 the IPageContent interface. A page (aspx) must then be created that loads (using Page.LoadControl) the page template, and the page content. The page content adds itself to the page template. The page template is then added to the aspx's control...
4
2228
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 fields. These are UserName, UserEmail, UserCountry & Comments. It works well with all of those fields appearing in the body of an email that is sent to me. What I would now like is for the UserEmail field to appear in the "From:" field in the
9
3878
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 case statement like this: sub showHelp(byval frm as String) Select Case (frm) Case "Form1" dim help as new Form1
31
3206
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 some of the most powerful programming tools I have found. Often times as my program grows so do my objects. Often times I look back and see that my objects could be broken down int several smaller more re-usable module pieces of code. Is it a...
4
6707
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 you for your Feedback" for 5 second and then goes back to the home page... Below is the code for the feedback.php <?php /* CHFEEDBACK.PHP Feedback Form PHP Script Ver 2.08 Generated by thesitewizard.com's Feedback Form Wizard. ...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.