473,695 Members | 2,278 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 1423
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
4101
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
2285
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
2471
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
5573
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
2057
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
1639
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
2730
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
2371
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
2568
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
3364
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
8586
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
8864
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
7683
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
6506
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
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
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
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.