473,386 Members | 1,741 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.

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 1403
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.