473,605 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a workable script out there for formmail for php 5?

dreamcatcher
16 New Member
Hi everyone,

I'm a frontend designer starting to learn about getting forms to work. What I'm after is a script that I can learn from and get working on a site relatively quickly. Something that has the 'how to' details with the script, explaining stuff. A simple feedback form, that displays something similar to what I'm showing below. I need this script to generate an e-mail that is sent back to the visitor saying, thank you etc for your query. Would the same script work for creating a join e-mail database form ? Am I right in saying that?

Can anyone recommend a thorough tutorial with actual working scripts for php 5? My server supports php 5.

Much Appreciation. S

[HTML]<form action="" method="" name="" target="" id="" onsubmit="" >
<p><label for="name">Full Name</label>
<input name="fullname" type="text" class="text" id="fullname" />
</p>
<p><label for="email">E-Mail</label>
<input name="email" type="text" class="text" id="email" />
</p>
<p><label for="phone">Pho ne No.</label>
<input name="phone_no" type="text" class="text" id="phone_no" />
</p>
<p>
<label for="subject">S elect subject</label>
<select name="subject" class="text" id="subject">
<option selected="selec ted">Select subject</option>
<option value="design"> Design</option>
<option value="developm ent">Developmen t</option>
<option value="identity ">Brand Identity</option>
<option value="marketin g">Online Marketing</option>
<option value="question ">General Question</option>
</select></p>
<p><label for="question"> Your Question.</label>
<textarea name="question" cols="30" rows="10" id="question" class="text"></textarea>
</p>
<p><input name="Submit" class="submit" type="submit" value="submit" /><input name="reset" type="reset" value="reset" />
</p></form>[/HTML]
Nov 18 '06 #1
4 4059
ronverdonk
4,258 Recognized Expert Specialist
Have a look at the tutorial at Send Email from a PHP Script
and another one at Geekz http://lampgeekz.netgeekz.net/forum/...opic,38.0.html

Ronald :cool:
Nov 18 '06 #2
TheMadMidget
98 New Member
Important info if you want to have the from address user inputed!

Copied from W3Schools:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <?php
  5. if (isset($_REQUEST['email']))
  6. //if "email" is filled out, send email
  7.   {
  8.   //send email
  9.   $email = $_REQUEST['email'] ; 
  10.   $subject = $_REQUEST['subject'] ;
  11.   $message = $_REQUEST['message'] ;
  12.   mail("someone@example.com", "Subject: $subject",
  13.   $message, "From: $email" );
  14.   echo "Thank you for using our mail form";
  15.   }
  16. else
  17. //if "email" is not filled out, display the form
  18.   {
  19.   echo "<form method='post' action='mailform.php'>
  20.   Email: <input name='email' type='text' /><br />
  21.   Subject: <input name='subject' type='text' /><br />
  22.   Message:<br />
  23.   <textarea name='message' rows='15' cols='40'>
  24.   </textarea><br />
  25.   <input type='submit' />
  26.   </form>";
  27.   }
  28. ?>
  29.  
  30. </body>
  31. </html>
  32.  
The problem with the code above is that unauthorized users can insert data into the mail headers via the input form.

What happens if the user adds the following text to the email input field in the form?
Expand|Select|Wrap|Line Numbers
  1. someone@example.com%0ACc:person2@example.com
  2. %0ABcc:person3@example.com,person3@example.com,
  3. anotherperson4@example.com,person5@example.com
  4. %0ABTo:person6@example.com
  5.  
The mail() function puts the text above into the mail headers as usual, and now the header has an extra Cc:, Bcc:, and To: field. When the user clicks the submit button, the e-mail will be sent to all of the addresses above!

The best way to stop e-mail injections is to validate the input.

Now we have added an input validator that checks the email field in the form:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <?php
  5. function spamcheck($field)
  6.   {
  7. //eregi() performs a case insensitive regular expression match
  8.   if(eregi("to:",$field) || eregi("cc:",$field)) 
  9.     {
  10.     return TRUE;
  11.     }
  12.   else
  13.     {
  14.     return FALSE;
  15.     }
  16.   }
  17.  
  18. //if "email" is filled out, send email
  19. if (isset($_REQUEST['email']))
  20.   {
  21.   //check if the email address is invalid
  22.   $mailcheck = spamcheck($_REQUEST['email']);
  23.   if ($mailcheck==TRUE)
  24.     {
  25.     echo "Invalid input";
  26.     }
  27.   else
  28.     { 
  29.     //send email
  30.     $email = $_REQUEST['email'] ; 
  31.     $subject = $_REQUEST['subject'] ;
  32.     $message = $_REQUEST['message'] ;
  33.     mail("someone@example.com", "Subject: $subject",
  34.     $message, "From: $email" );
  35.     echo "Thank you for using our mail form";
  36.     }
  37.   }
  38. else
  39. //if "email" is not filled out, display the form
  40.   {
  41.   echo "<form method='post' action='mailform.php'>
  42.   Email: <input name='email' type='text' /><br />
  43.   Subject: <input name='subject' type='text' /><br />
  44.   Message:<br />
  45.   <textarea name='message' rows='15' cols='40'>
  46.   </textarea><br />
  47.   <input type='submit' />
  48.   </form>";
  49.   }
  50. ?>
  51.  
  52. </body>
  53. </html>
  54.  
Nov 20 '06 #3
dreamcatcher
16 New Member
Have a look at the tutorial at Send Email from a PHP Script
and another one at Geekz http://lampgeekz.netgeekz.net/forum/...opic,38.0.html

Ronald :cool:
Thanks for those suggestions Ronald, I checked out the tutorials on about.com and set up the php, seems to be working fine. I've put it to work on www.zofocreativ e.com/zofo_creative_e nquiry_form.htm . Yea, I found the about tutorials managable, as I'm not a php programmer, so I'm delighted with the result and to be able to do it myself without getting my programmers to to it. Cheers, nice one.
Nov 26 '06 #4
ronverdonk
4,258 Recognized Expert Specialist
And do not forget to sanitize ALL fields. The sample that themadmidget supplied is a good example of spam prevention.

But you must also verify the 'correctness' of the email address[php]function valid_email ($str) {
return (ereg ('(^[0-9a-zA-Z_\.-]{1,}@([0-9a-zA-Z_\-]{1,}\.)+[0-9a-zA-Z_\-]{2,}$)', $str));
}[/php]
and minimally cleanse the subject and message fields, like this:[php]
$subject = strip_tags($_RE QUEST['subject'] );
$message = strip_tags($_RE QUEST['message'] );[/php]
Ronald :cool:
Nov 26 '06 #5

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

Similar topics

2
3320
by: Web Master | last post by:
Hi, I am having a little issue with Jacks Form mail php script. I have installed it and configured the form to get it to work, but for some bizarre reason I have 2 issues I can't seem to debug. Issue#1: I get 2 copies of the form that gets submitted each time. Issue#2: The header does not display the "FROM" information in Outlook, but I can see the From information in my email spam filter
4
4329
by: Ann | last post by:
Hi, I am trying to send a html email from a php script. This script emails a common information to all the members in the database. The only problem is I cannot specify colors, hyperlinks etc..Html tags like <h1></h1>, <br/>, <b> etc works though.. Could any one tell me what i might be doing wrong? Any help will be greatly appreciated.
24
2707
by: Jane Withnolastname | last post by:
I have a very simple navigation "menu" in the middle of my page. It is three simple links and it lays out horizontally. To achieve this, I used the following table: <table align=center width="40%"> <tr> <td align=left width="13%"><a href="#auctions">Auctions</a></td> <td align=center width="13%"><a href="gallery.htm">Gallery</a></td> <td align=right width="13%"><a href="mailto:JaneWithnolastnameNOSPAM@yahoo.com">Contact</a></td>
4
2962
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text email by creating a text file, with content following certain format, and saving that file into the correct '..\mailroot\pickup' folder, and it is working fine
2
4889
by: Margaret Werdermann | last post by:
Hi all: I'm having a nasty time with a particularly difficult piece of code and was hoping someone might be able to help me. I have a FormMail form that originally worked perfectly. Then, I had to add a JavaScript function to the Submit button to make a server function run when the form was submitted. Unfortunately, this JavaScript wouldn't run when the button was designated as a Submit, so I changed the button and placed a...
2
4765
by: fleemo17 | last post by:
It's been a while since I had to set up a form on a site. Is Matt's FormMail script still a good choice, or are there better options available these days? -F
2
1486
by: Rico | last post by:
Hello, I'm using formmail.asp which is an emailing utility. Basically, the user fills out a request page, clicks "Submit" and the page posts to formmail.asp which emails the user information. I'm running IIS5 on a Win2k server box and recently ran the Windows Updates (the last time I do that). Anyway, that emailing form doesn't work now on any of the sites I host. Any ideas?
1
1628
by: willmore | last post by:
Is sendmail the same as formmail ? I have a cgi scripr that need a path to sendmail, but on my server are insted Formmail. BG Willmore
20
1713
by: Pete Marsh | last post by:
Wondering if anyone can see an error with this script. I get a server configuration error. THat could mean a module is not being loaded, but maybe there's a syntax error here, can anyone spot it? Thanks <? Error_Reporting(E_ALL & ~E_NOTICE); $subject="from ".$_REQUEST ; $headers= "From: ".$_REQUEST ."\n"; $headers.='Content-type: text/html; charset=iso-8859-1';
0
8004
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
8425
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
8418
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
8288
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
6743
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
5886
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
5445
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
3912
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...
1
1541
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.