473,406 Members | 2,956 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,406 software developers and data experts.

PHP form send random blank emails

Form works fine, occasionally get blank emails.

Form Code
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script type="text/javascript">
  5. <!--
  6. function MM_validateForm() { //v4.0
  7.   if (document.getElementById){
  8.     var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  9.     for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
  10.       if (val) { nm=val.name; if ((val=val.value)!="") {
  11.         if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  12.           if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  13.         } else if (test!='R') { num = parseFloat(val);
  14.           if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  15.           if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  16.             min=test.substring(8,p); max=test.substring(p+1);
  17.             if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  18.       } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  19.     } if (errors) alert('The following error(s) occurred:\n'+errors);
  20.     document.MM_returnValue = (errors == '');
  21. } }
  22. //-->
  23. </script>
  24. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  25. <meta http-equiv="Page-Enter" content="revealtrans(duration=0.0)" />
  26. <meta http-equiv="Page-Exit" content="revealtrans(duration=0.0)" />
  27. <link href="css/style-mcd.css" rel="stylesheet" type="text/css" />
  28. <link href="colorbox/css/colorbox.css" rel="stylesheet" type="text/css" />
  29. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  30. <script type="text/javascript" src="http://www.red-dogs.com/colorbox/js/jquery.colorbox.js"></script> 
  31. <script type="text/javascript">
  32. $(document).ready(function(){
  33. $("a[rel='image']").colorbox();
  34. $("#click").click(function(){ 
  35. $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
  36. return false;
  37. });
  38. });
  39. </script>
  40. </head>
  41. <body>
  42. <div id="pageContainer">
  43. <div id="header">
  44. <div class="logo"><a href="http://www.mouseclickdesigns.com"><img src="images/logo.jpg" alt="Cincinnati Website Design" title="Cincinnati Web Design" width="346" height="70" /></a></div>
  45. </div>
  46. <div id="content">
  47. <div id="leftColumn">
  48. <div class="text">
  49. <h1>Welcome to MCD</h1>
  50. <p>Thank you for visiting our site. We are a professional web design firm specializing in affordable custom website design for small businesses. </p>
  51. </div>
  52. <div style="clear: both"></div>
  53. <p><span class="redText"><strong>Notice</strong></span><br />
  54. At this time, we are not taking on any new clients until May. Please feel free to contact us with any questions until then. We look forward to hearing about your project.</p>
  55. <h2><br />
  56. Recent Projects<br />
  57. </h2>
  58. <div class="colorboxPic"><a href="images/lrg-belle-meade.jpg" rel="image" title="Belle Meade"><img src="images/thumb-belle-meade.jpg" width="191" height="115" alt="Belle Meade" /></a></div>
  59. <div class="colorboxPic"><a href="images/lrg-shooters.jpg" rel="image" title="Shooters Sports Grill"><img src="images/thumb-shooters.jpg" width="191" height="115" alt="Shooters Sports Grill" /></a></div>
  60. <div class="colorboxPic"><a href="images/lrg-sola.jpg" rel="image" title="Sola Winery"><img src="images/thumb-sola.jpg" width="191" height="115" alt="Sola Winery" /></a></div>
  61. </div>
  62. <div id="rightColumn">
  63. <span class="contactFormTitle">Get in Touch</span><br />
  64. <p><script type="text/javascript">
  65. /*<![CDATA[*/
  66. /***********************************************
  67. * http://www.dynamicdrive.com/emailriddler/
  68. * **********************************************/
  69. var emailriddlerarray=[105,110,102,111,64,109,111,117,115,101,99,108,105,99,107,100,101,115,105,103,110,115,46,99,111,109]
  70. var encryptedemail_id38='' //variable to contain encrypted email 
  71. for (var i=0; i<emailriddlerarray.length; i++)
  72. encryptedemail_id38+=String.fromCharCode(emailriddlerarray[i])
  73. document.write('<a href="mailto:'+encryptedemail_id38+'?subject=Message from Website"><img src="images/phone-email.gif" alt="Email Us" title="Email Us"/></a>')
  74. /*]]>*/
  75. </script></p>
  76. <div id="contact-form">
  77. <form action="mcd0310.php" method="post" onsubmit="MM_validateForm('visitor','','R','visitormail','','RisEmail','inquiry','','R');return document.MM_returnValue" ><?php
  78. $ipi = getenv("REMOTE_ADDR");
  79. $httprefi = getenv ("HTTP_REFERER");
  80. $httpagenti = getenv ("HTTP_USER_AGENT");
  81. ?>
  82. <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
  83. <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
  84. <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
  85. Name: (Required)<br />
  86. <input name="Name" type="text" class="contact-fields" id="visitor" size="50" /><br />
  87. Email: (Required)<br />
  88. <input name="Email" type="text" class="contact-fields" id="visitormail" size="50" /><br />
  89. Company/Organization:<br />
  90. <input name="Company" type="text" class="contact-fields" id="company" size="50" /><br />
  91. Message: (Required)<br />
  92. <textarea name="Message" cols="1" rows="4" class="contact-multiline" id="inquiry"></textarea>
  93. <br />
  94. <br />
  95. <input type="submit" value="Submit Form" />
  96. </form>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div style="clear: both"></div>
  102. <div id="footerContainer">
  103. <div id="footerLeft"><img src="images/footer.gif" alt="" width="304" height="34" border="0" usemap="#Map" />
  104. <map name="Map" id="Map">
  105. <area shape="rect" coords="15,-3,151,37" href="http://www.mouseclickdesigns.com" alt="Mouse Click Designs" title="Mouse Click Designs" />
  106. <area shape="rect" coords="233,-4,307,38" href="http://twitter.com/mousetweets" alt="Follow MCD on Twitter" title="Follow MCD on Twitter" />
  107. <area shape="rect" coords="153,-2,231,32" href="http://www.facebook.com/pages/Mouse-Click-Designs/151522568199884" alt="&quot;Like&quot; Us on Facebook" title="&quot;Like&quot; Us on Facebook" />
  108. </map></div>
  109. </div>
  110. </body>
  111. </html>
PHP Script
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta name="robots" content="noindex, nofollow"/>
  5. <script type="text/javascript">
  6. <!--
  7. function MM_validateForm() { //v4.0
  8.   if (document.getElementById){
  9.     var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  10.     for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
  11.       if (val) { nm=val.name; if ((val=val.value)!="") {
  12.         if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  13.           if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  14.         } else if (test!='R') { num = parseFloat(val);
  15.           if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  16.           if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  17.             min=test.substring(8,p); max=test.substring(p+1);
  18.             if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  19.       } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  20.     } if (errors) alert('The following error(s) occurred:\n'+errors);
  21.     document.MM_returnValue = (errors == '');
  22. } }
  23. //-->
  24. </script>
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  26. <meta http-equiv="Page-Enter" content="revealtrans(duration=0.0)" />
  27. <meta http-equiv="Page-Exit" content="revealtrans(duration=0.0)" />
  28. <link href="css/style-mcd.css" rel="stylesheet" type="text/css" />
  29. <link href="colorbox/css/colorbox.css" rel="stylesheet" type="text/css" />
  30. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  31. <script type="text/javascript" src="http://www.red-dogs.com/colorbox/js/jquery.colorbox.js"></script> 
  32. <script type="text/javascript">
  33. $(document).ready(function(){
  34. $("a[rel='image']").colorbox();
  35. $("#click").click(function(){ 
  36. $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
  37. return false;
  38. });
  39. });
  40. </script>
  41. </head>
  42. <body>
  43. <div id="pageContainer">
  44. <div id="header">
  45. <div class="logo"><a href="http://www.mouseclickdesigns.com"><img src="images/logo.jpg" alt="Cincinnati Website Design" title="Cincinnati Web Design" width="346" height="70" /></a></div>
  46. </div>
  47. <div id="content">
  48. <?php
  49. $ip = $_POST['ip']; 
  50. $httpref = $_POST['httpref']; 
  51. $httpagent = $_POST['httpagent']; 
  52. $visitor = $_POST['Name']; 
  53. $visitormail = $_POST['Email']; 
  54. $company = $_POST['Company']; 
  55. $inquiry = $_POST['Message'];
  56. if (eregi('http:', $inquiry)) {
  57. die ();
  58. }
  59. $todayis = date("l, F j, Y, g:i a") ;
  60. $subject = "Website Contact Form"; 
  61. $inquiry = stripcslashes($inquiry); 
  62. $message = "$todayis [EST] \n
  63. NAME: $visitor ($visitormail)\n
  64. COMPANY: $company \n 
  65. INQUIRY: $inquiry \n 
  66. ";
  67. $from = "From: $visitormail\r\n";
  68. mail("sarahaustin@fuse.net", $subject, $message, $from);
  69. ?>
  70. <div id="leftColumn">
  71. <div class="text">
  72. <h3>Your Message Has Been Submitted!</h3>
  73. <p>Thank you for your interest in <a href="http://www.mouseclickdesigns.com/mouse-click-designs.html">Mouse Click Designs</a>.  We will be in touch with you shortly. </p>
  74. <p>Have a great day!</p>
  75. </div>
  76. <div style="clear: both"></div>
  77. <p><span class="redText"><strong>Notice</strong></span><br />
  78. At this time, we are not taking on any new clients until May. Please feel free to contact us with any questions until then. We look forward to hearing about your project.</p>
  79. <h2><br />
  80. Recent Projects<br />
  81. </h2>
  82. <div class="colorboxPic"><a href="images/lrg-belle-meade.jpg" rel="image" title="Belle Meade"><img src="images/thumb-belle-meade.jpg" width="191" height="115" alt="Belle Meade" /></a></div>
  83. <div class="colorboxPic"><a href="images/lrg-shooters.jpg" rel="image" title="Shooters Sports Grill"><img src="images/thumb-shooters.jpg" width="191" height="115" alt="Shooters Sports Grill" /></a></div>
  84. <div class="colorboxPic"><a href="images/lrg-sola.jpg" rel="image" title="Sola Winery"><img src="images/thumb-sola.jpg" width="191" height="115" alt="Sola Winery" /></a></div>
  85. </div>
  86. <div id="rightColumn">
  87. <span class="contactFormTitle">Get in Touch</span><br />
  88. <p><script type="text/javascript">
  89. /*<![CDATA[*/
  90. /***********************************************
  91. * http://www.dynamicdrive.com/emailriddler/
  92. * **********************************************/
  93. var emailriddlerarray=[105,110,102,111,64,109,111,117,115,101,99,108,105,99,107,100,101,115,105,103,110,115,46,99,111,109]
  94. var encryptedemail_id38='' //variable to contain encrypted email 
  95. for (var i=0; i<emailriddlerarray.length; i++)
  96. encryptedemail_id38+=String.fromCharCode(emailriddlerarray[i])
  97. document.write('<a href="mailto:'+encryptedemail_id38+'?subject=Message from Website"><img src="images/phone-email.gif" alt="Email Us" title="Email Us"/></a>')
  98. /*]]>*/
  99. </script></p>
  100. <div id="contact-form">
  101. <form action="mcd0310.php" method="post" onsubmit="MM_validateForm('visitor','','R','visitormail','','RisEmail','inquiry','','R');return document.MM_returnValue" ><?php
  102. $ipi = getenv("REMOTE_ADDR");
  103. $httprefi = getenv ("HTTP_REFERER");
  104. $httpagenti = getenv ("HTTP_USER_AGENT");
  105. ?>
  106. <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
  107. <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
  108. <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
  109. Name: (Required)<br />
  110. <input name="Name" type="text" class="contact-fields" id="visitor" size="50" /><br />
  111. Email: (Required)<br />
  112. <input name="Email" type="text" class="contact-fields" id="visitormail" size="50" /><br />
  113. Company/Organization:<br />
  114. <input name="Company" type="text" class="contact-fields" id="company" size="50" /><br />
  115. Message: (Required)<br />
  116. <textarea name="Message" cols="1" rows="4" class="contact-multiline" id="inquiry"></textarea>
  117. <br />
  118. <br />
  119. <input type="submit" value="Submit Form" />
  120. </form>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <!-- End right-column -->
  126. <div style="clear: both"></div>
  127. <div id="footerContainer">
  128. <div id="footerLeft"><img src="images/footer.gif" alt="" width="304" height="34" border="0" usemap="#Map" />
  129. <map name="Map" id="Map">
  130. <area shape="rect" coords="15,-3,151,37" href="http://www.mouseclickdesigns.com" alt="Mouse Click Designs" title="Mouse Click Designs" />
  131. <area shape="rect" coords="233,-4,307,38" href="http://twitter.com/mousetweets" alt="Follow MCD on Twitter" title="Follow MCD on Twitter" />
  132. <area shape="rect" coords="153,-2,231,32" href="http://www.facebook.com/pages/Mouse-Click-Designs/151522568199884" alt="&quot;Like&quot; Us on Facebook" title="&quot;Like&quot; Us on Facebook" />
  133. </map></div>
  134. </div>
  135. </body>
  136. </html>
Mar 13 '11 #1
5 3481
The way you script is setup it will send out an email every time the page is loaded or refreshed.
Consider placing the part of code that send the email in a condition like...
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['Message'])) {
  2. //Send email
  3. }
And it's a good practice to place code like sending email isolated page that doesn't generate any output, then after it completes it's task redirect the page to another that display the result.
(This helps to void resending the email when page is refreshed)
Mar 13 '11 #2
Ok...if I manually refresh the page, it does not send out a blank email. So I am confused as to what you are saying?
Mar 15 '11 #3
Try adding an echo() just before the mail() to see if the execution reach that in a situation you don't want it to.
Mar 15 '11 #4
Ok... I am not a php programmer. I stuggled to get this form put together. Are you saying above to scrap your orginal amswer and just add echo () nothing in the parenthises, in front of the mail?
Mar 17 '11 #5
dgreenhouse
250 Expert 100+
The echo is just for debugging purposes...
That should not be on the production site after you've gotten the app working.

I'm assuming that you want something like this:
(Hover to view image)



I know it can be very frustrating when you don't know exactly what you're doing; which is my experience most of the time :-), but you'll get it eventually.

From the looks of it, you need to clean up your logic a bit and it also appears that the two files are duplicating php, javascript, and html unnecessarily.
Mar 17 '11 #6

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

Similar topics

4
by: sean | last post by:
HI All, I have a function that validates a form, when the function returns true or false it still does not submit the form. I am using a <div> tag with text to submit the form. I have tried the...
1
by: Mike Cooper | last post by:
Hello all, I was working on the update portion of my Access database input form. The add and view functions were working just fine. I did not touch the form_load event function or anything...
1
by: Bob Bedford | last post by:
Hello all, I've to send some reports to a mailing list. Those reports must be created by datas stored in mysql, using PHP. - my first idea is to create PDF files that can be sent by email or...
13
by: bmurphy | last post by:
Last week after much searching, I found the answer to my problem in this newsgroup. I can't find the thread from which I got my solution, but I wanted to report back what worked. When the site...
1
by: Neal Becker | last post by:
Any ideas on python packages that could help with sending gpg encrypted (properly mime formatted) emails? My idea is to forward all my emails to a remote imap server, but gpg encrypt them to...
0
by: sheel331 | last post by:
Hello, I am new to coding in vb.net and have run into an issue with some code that I am looking over. This is a webform that is filled out and once it is filled out, it takes the responses from...
2
by: lstanikmas | last post by:
Hi, I'm validating a form with this ASP but receiving some blank email responses; does anyone see anything wrong with it?: function isFormVarExcluded(thisForm, strToCheck) { var strExcludeVars...
1
by: lrw0831 | last post by:
I have the main form where employees enter "issues". Some issues have fields that are the same. My fields are Issue ID (auto) Product Entered BY Issue Type Priority Request from Status...
1
by: Lelu | last post by:
Hi, My HTML form is generating some blank email responses; does anyone see anything wrong with the scripts?: function isFormVarExcluded(thisForm, strToCheck) { var strExcludeVars =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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...

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.