472,809 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Forms

30
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\Goldfish Graphics\contact.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 1360
pbmods
5,821 Expert 4TB
Please use CODE tags when posting source code. Thanks!
Jul 19 '07 #2
pbmods
5,821 Expert 4TB
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
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 Expert 4TB
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
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...
3
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...
7
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...
13
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()...
15
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...
3
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. ...
8
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...
3
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...
6
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...
21
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.