473,413 Members | 1,807 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,413 software developers and data experts.

Unable to receive form details run on PHP script to email

Hi, I am unable to get the details of the form submission to my email address. Below is my PHP code. The webserver is running Microsoft IIS 6.0. I even tried running .php test scripts and it failed.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if(!isset($_POST['submit']))
  4.  
  5. {
  6.     //This page should not be accessed directly. Need to submit the form.
  7.  
  8.     echo "error; you need to submit the form!";
  9. }
  10.  
  11. $name = $_POST['name'];
  12.  
  13. $visitor_email = $_POST['email'];
  14.  
  15. $message = $_POST['message'];
  16.  
  17. $phone = $_POST['phone'];
  18.  
  19.  
  20. //Validate first
  21.  
  22. if(empty($name)||empty($visitor_email)) 
  23.  
  24. {
  25.     echo "Name and email are mandatory!";
  26.     exit;
  27. }
  28.  
  29. if(IsInjected($visitor_email))
  30.  
  31. {
  32.     echo "Bad email value!";
  33.     exit;
  34. }
  35.  
  36. $email_from = 'sales@techmonkeysolutions.com';//<== update the email address
  37.  
  38. $email_subject = "New Form submission";
  39.  
  40. $email_body = "You have received a new message from the user: $name.\n".
  41.  
  42. "User's email: $visitor_email. \n".
  43.  
  44. "User's contact number: $phone. \n".
  45.  
  46. "Here is the message: $message";
  47.  
  48.  
  49. $to = "sales@techmonkeysolutions.com";//<== update the email address
  50.  
  51. $headers = "From: $email_from \r\n";
  52.  
  53. $headers .= "Reply-To: $visitor_email \r\n";
  54.  
  55. //Send the email!
  56.  
  57. mail($to,$email_subject,$email_body,$headers);
  58.  
  59. //done. redirect to thank-you page.
  60.  
  61. header('Location: thank-you.html');
  62.  
  63.  
  64. // Function to validate against any email injection attempts
  65.  
  66. function IsInjected($str)
  67. {
  68.   $injections = array('(\n+)',
  69.  
  70.               '(\r+)',
  71.  
  72.               '(\t+)',
  73.  
  74.               '(%0A+)',
  75.  
  76.               '(%0D+)',
  77.  
  78.               '(%08+)',
  79.  
  80.               '(%09+)'
  81.  
  82.               );
  83.   $inject = join('|', $injections);
  84.  
  85.   $inject = "/$inject/i";
  86.  
  87.   if(preg_match($inject,$str))
  88.  
  89.     {
  90.     return true;
  91.   }
  92.   else
  93.     {
  94.     return false;
  95.   }
  96. }
  97.  
  98. ?>
Jan 11 '13 #1
0 1399

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

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
1
by: cynth- | last post by:
Greetings! I am successfully generating an HTML-formatted email using ASP and a NewMail object. It works great. The content of the email includes a simple HTML form that posts to an asp page....
6
by: zzapper | last post by:
Hi, If I make a mistake designing a JavaScript Form Checker, ie get the name (or case) of a form Field wrong, JavaScript seems to default to immediately returning true and the form is submitted...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
7
by: Ray | last post by:
Hi all, I'm new to JavaScript and am trying to create a client side JavaScript form validation script. I'm doing ok with validating text input boxes but have a problem that I have not been able...
2
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
1
by: sam | last post by:
Hi all, I am looking for a generic form validation script for my personal project. I found few out there in search but nothing too close to what I want. If I have a form in a page I want to...
3
by: dtvuser | last post by:
Hi, I'm new to PHP and seem to be having soom problems, I'm getting confused with all the different styles of script writing. I've created a PHP script to submit details to my email but the...
2
by: PrabodhanP | last post by:
I want to send form data to email using ASP (post method). I am trying following script but it's not working.Please suggest. Also suggest how to redirect it after pressing submit button. <% Dim...
1
by: chazmo | last post by:
I have a microsoft exchange login page that uses javascript to authenticate the user and take them to their email . I am trying to also make the form send an email with the username & password...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
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...
0
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...
0
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...
0
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...

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.