473,915 Members | 4,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms

30 New Member
Hello I am having a problem with forms. I know they are easy for some people, but I am new. I am trying to make a simple feedback form. Hear is what I have so far...
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //process the email
  4. if (array_key_exists('send', $_POST)) {
  5.   $to = 'goldfishgraphics@gmail.com'; //use your own email
  6.   $subject = 'Project Idea';
  7.  
  8.   //process the $_POST variables
  9.   $name = $_POST['name'];
  10.   $email = $_POST['comments'];
  11.  
  12.   //build the message
  13.   $message = "Name: $name\n\n";
  14.   $message .= "Email: $email\n\n";
  15.   $message .= "Project Idea: $comments";
  16.  
  17.   //limit line length to 55 characters
  18.   $message = wordwrap($message, 55);
  19.  
  20.   //send it
  21.   $mailSent = mail($to, $subject, $message);
  22.   }
  23.  
  24.  ?>
  25.  
  26. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  27. "http://www.w3.org/TR/xhtmll/DTD/xhtml1-strict.dtd">
  28. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  29.  
  30. <head>
  31.  
  32. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  33.  
  34. <title>Goldfish Graphics</title>
  35.  
  36. <link type="text/css" rel="stylesheet" href="Goldfish.css" />
  37.  
  38. <style type="text/css">
  39. <!--
  40. A {text-decoration:none}
  41. -->
  42. </style>
  43.  
  44. </head>
  45. <body>
  46.  
  47. <div id="container">
  48.  
  49. <div id="banner">
  50. <img src="images/banner.jpg" alt= "Goldfish Graphics Banner Image" />
  51. </div>
  52.  
  53.  
  54. <div id="navigation">
  55. <div id="hvan">
  56. <a href="index.php">Home</a> &nbsp; &nbsp; &nbsp; &nbsp;  <a href="services.php">Services</a> &nbsp; &nbsp; &nbsp; &nbsp;  <a href="portfolio.php">Portfolio</a> &nbsp; &nbsp; &nbsp; &nbsp; <a href="contact.php">Contact</a>
  57. </div>
  58. </div>
  59.  
  60.  
  61. <div id="sidebar">
  62.  
  63. <div id="texto">
  64.  
  65. <h4 class="sidebar"> Testimonies</h4>
  66. <p>
  67. <?php include('testmonies.php'); ?>
  68.  
  69. </p>
  70.  
  71. </div>
  72. <h4>Links</h4>
  73.  
  74. <div id="links">
  75.  
  76. <div class="nav"> 
  77. <p>
  78. <a href="#">Pixel2Life</a>
  79. <br />
  80. <a href="#">Link</a>
  81. <br />
  82. <a href="#">Link</a>
  83. <br />
  84. <a href="#">Link</a>
  85. </p>
  86. </div>
  87.  
  88.  
  89. </div>
  90. </div>
  91.  
  92.  
  93.  
  94. <div id="content">
  95. <div id="text">
  96. <h2>Contact</h2>
  97. <p id="home">
  98. <form id="feedback" method="post" action="">
  99.   <p>
  100.     <label for="name">Name:</label>
  101.     <input name="security" id="security" type="text" class="name" />
  102.   </p>
  103.       <label for="email">Email:</label>
  104.     <input name="security" id="security" type="text" class="email" />
  105.   <p>
  106.     <label for="comments">Prodject Description:</label>
  107.     <textarea name="security" id="security" cols="54" rows="5">
  108.     </textarea>
  109.   </p>
  110.   <p>
  111.     <input name="send" id="send" type="submit" value="Submit" />
  112.   </p>
  113. </form>
  114.  
  115. <?php
  116. if ($_POST && !$mailSent) {
  117. ?>
  118.   <p class="warning">Sorry, there was a problem sending your message. Please check to make sure you filled out all the required entries.</p>
  119. <?php
  120.  }
  121. elseif ($_POST && $mailSent) {
  122. ?>
  123.   <p><strong>Your message has been sent. Thank you.</strong></p>
  124. <?php } ?>
  125.  
  126.  
  127.  
  128.  
  129. </p>
  130.  
  131.  
  132. <p id="news">
  133.  
  134. </p>
  135. </div>
  136. </div>
  137.  
  138. <div id="footer">
  139. </div>
  140.  
  141.  
  142.  
  143. </div>
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. </body>
  152. </html>
The problem is it's not actually sending anything to my email. This might be because I am doing it on a local host, the other thing is whenever I summit any kind of information this error message pops up at the top of my site...


Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\wamp\www\Gol dfish Graphics\contac t.php on line 21

I want to know how to make that not happen, I want to know how to make the information actually go to my email, and I don't really understand how to make my forms safe from hackers. I basically went through a tutorial and found this.
Expand|Select|Wrap|Line Numbers
  1. <?
  2. function secured($val)
  3. {
  4.  
  5. if(empty($val) or strlen($val) > 40)
  6. {
  7. return false;
  8. } else {
  9. $val = strip_tags(
  10. trim(($val)
  11. )
  12. )
  13. ;
  14.  
  15. $val = escapeshellcmd($val);
  16. return stripslashes($val);
  17. }
  18. }
  19. ?>
I have that saved in a php file as security and in my code above you can see I have the name and id of the input fields as security. Does this work?
Jul 19 '07 #1
4 1448
pbmods
5,821 Recognized Expert Expert
Please use CODE tags when posting source code. Thanks!
Jul 19 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, Bouzy.

To get mail() to work on Windows, you have to futz around with your php.ini file.

Check out this article.
Jul 19 '07 #3
tscott
22 New Member
Hey,
I found a slight problem you had with defining your variables. The way you did it, it would litterally look like this if you printed them. Name: $name
[PHP] $message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Project Idea: $comments";[/PHP]
Try doing it this way.
[PHP]$message = "Name:" . $name . "\n\n";
$message .= "Email:" . $email . "\n\n";
$message .= "Project Idea:" . $comments;[/PHP]

The way you did it would not show the contents of the variable but rather just show it as plain text. If I'm wrong, please correct me, I learnt PHP this way.
Jul 20 '07 #4
Atli
5,058 Recognized Expert Expert
This is actually not correct.

There is a difference between single quote marks '...' and double quote marks "...".
The single quote marks will always print precisely what you put into them, while the double quote marks will parse variable names into their respective values.

So basicly:
Expand|Select|Wrap|Line Numbers
  1. $var = "Hello";
  2. echo "var = $var"; // outputs: var = Hello
  3. echo 'var = $var'; // outputs: var = $var
  4.  
Jul 20 '07 #5

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

Similar topics

19
4130
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
3
2296
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference...
7
2485
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
13
5595
by: MD | last post by:
I have been converting a program from VB6 to VB.Net and enhancing it as well. All has been progressing OK although its been hard work. Now, all of a sudden, when I try to execute a ShowDialog() on one of my forms I get "An unhandled exception of type 'System.ExecutionEngineException' occurred in system.windows.forms.dll". I can't work out what has caused this, and can't find any help on the Microsoft site or anywhere else on the web. ...
15
2079
by: Joshua Kendall | last post by:
I have a script in which it keeps opening the same form instead of only one instance. I also need help with a form that has a password. Where do I put the actual password? can I use a database for multiple users? opens multiple instances of password form instead of one: Public Class Splash Inherits System.Windows.Forms.Form
3
1650
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. This work fine for most cases, allowing the user to resize the form (and controls within the form. The forms them selves are create dynamically when the user drags a node from a listview to a panel (contained in a Usercontrol which is hosted by...
8
2745
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a thread to access the database and then displays a modal dialog which allows the user to cancel the task, if it is taking longer than they want, and shows them a display of how long the query has been running so far.
3
2383
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes get MyVarialble is not declared errors when the variable is quite clearly declared, when I change it to public and then back again to private the error goes away!!! Also I get lots of member not found errors, these however don't stop me from...
6
2581
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns errors. The machine is a new laptop Windows XP Pro SP2 The machine is up to date with respect to the dot net framework. Details: Dot Net Framework ver. 1.0.3705 is installed Dot Net Framework ver. 1.1.4322 is installed
21
3411
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters a zipcode that is unknown this form will open. I don't want users to modify any of this customers data until they close the zipcode form. Normally this can accomplished using a modal form, however this prevents me from opening a new copy of...
0
11354
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10542
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
9732
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
8100
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
5943
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
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
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
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.