PHP form send random blank emails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Austin Webb
    New Member
    • Mar 2011
    • 3

    PHP form send random blank emails

    Form works fine, occasionally get blank emails.

    Form Code
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript">
    <!--
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
        } if (errors) alert('The following error(s) occurred:\n'+errors);
        document.MM_returnValue = (errors == '');
    } }
    //-->
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Page-Enter" content="revealtrans(duration=0.0)" />
    <meta http-equiv="Page-Exit" content="revealtrans(duration=0.0)" />
    <link href="css/style-mcd.css" rel="stylesheet" type="text/css" />
    <link href="colorbox/css/colorbox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="http://www.red-dogs.com/colorbox/js/jquery.colorbox.js"></script> 
    <script type="text/javascript">
    $(document).ready(function(){
    $("a[rel='image']").colorbox();
    $("#click").click(function(){ 
    $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
    return false;
    });
    });
    </script>
    </head>
    <body>
    <div id="pageContainer">
    <div id="header">
    <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>
    </div>
    <div id="content">
    <div id="leftColumn">
    <div class="text">
    <h1>Welcome to MCD</h1>
    <p>Thank you for visiting our site. We are a professional web design firm specializing in affordable custom website design for small businesses. </p>
    </div>
    <div style="clear: both"></div>
    <p><span class="redText"><strong>Notice</strong></span><br />
    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>
    <h2><br />
    Recent Projects<br />
    </h2>
    <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>
    <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>
    <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>
    </div>
    <div id="rightColumn">
    <span class="contactFormTitle">Get in Touch</span><br />
    <p><script type="text/javascript">
    /*<![CDATA[*/
    /***********************************************
    * http://www.dynamicdrive.com/emailriddler/
    * **********************************************/
    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]
    var encryptedemail_id38='' //variable to contain encrypted email 
    for (var i=0; i<emailriddlerarray.length; i++)
    encryptedemail_id38+=String.fromCharCode(emailriddlerarray[i])
    document.write('<a href="mailto:'+encryptedemail_id38+'?subject=Message from Website"><img src="images/phone-email.gif" alt="Email Us" title="Email Us"/></a>')
    /*]]>*/
    </script></p>
    <div id="contact-form">
    <form action="mcd0310.php" method="post" onsubmit="MM_validateForm('visitor','','R','visitormail','','RisEmail','inquiry','','R');return document.MM_returnValue" ><?php
    $ipi = getenv("REMOTE_ADDR");
    $httprefi = getenv ("HTTP_REFERER");
    $httpagenti = getenv ("HTTP_USER_AGENT");
    ?>
    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
    Name: (Required)<br />
    <input name="Name" type="text" class="contact-fields" id="visitor" size="50" /><br />
    Email: (Required)<br />
    <input name="Email" type="text" class="contact-fields" id="visitormail" size="50" /><br />
    Company/Organization:<br />
    <input name="Company" type="text" class="contact-fields" id="company" size="50" /><br />
    Message: (Required)<br />
    <textarea name="Message" cols="1" rows="4" class="contact-multiline" id="inquiry"></textarea>
    <br />
    <br />
    <input type="submit" value="Submit Form" />
    </form>
    </div>
    </div>
    </div>
    </div>
    <div style="clear: both"></div>
    <div id="footerContainer">
    <div id="footerLeft"><img src="images/footer.gif" alt="" width="304" height="34" border="0" usemap="#Map" />
    <map name="Map" id="Map">
    <area shape="rect" coords="15,-3,151,37" href="http://www.mouseclickdesigns.com" alt="Mouse Click Designs" title="Mouse Click Designs" />
    <area shape="rect" coords="233,-4,307,38" href="http://twitter.com/mousetweets" alt="Follow MCD on Twitter" title="Follow MCD on Twitter" />
    <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" />
    </map></div>
    </div>
    </body>
    </html>
    PHP Script
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="robots" content="noindex, nofollow"/>
    <script type="text/javascript">
    <!--
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
        } if (errors) alert('The following error(s) occurred:\n'+errors);
        document.MM_returnValue = (errors == '');
    } }
    //-->
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Page-Enter" content="revealtrans(duration=0.0)" />
    <meta http-equiv="Page-Exit" content="revealtrans(duration=0.0)" />
    <link href="css/style-mcd.css" rel="stylesheet" type="text/css" />
    <link href="colorbox/css/colorbox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="http://www.red-dogs.com/colorbox/js/jquery.colorbox.js"></script> 
    <script type="text/javascript">
    $(document).ready(function(){
    $("a[rel='image']").colorbox();
    $("#click").click(function(){ 
    $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
    return false;
    });
    });
    </script>
    </head>
    <body>
    <div id="pageContainer">
    <div id="header">
    <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>
    </div>
    <div id="content">
    <?php
    $ip = $_POST['ip']; 
    $httpref = $_POST['httpref']; 
    $httpagent = $_POST['httpagent']; 
    $visitor = $_POST['Name']; 
    $visitormail = $_POST['Email']; 
    $company = $_POST['Company']; 
    $inquiry = $_POST['Message'];
    if (eregi('http:', $inquiry)) {
    die ();
    }
    $todayis = date("l, F j, Y, g:i a") ;
    $subject = "Website Contact Form"; 
    $inquiry = stripcslashes($inquiry); 
    $message = "$todayis [EST] \n
    NAME: $visitor ($visitormail)\n
    COMPANY: $company \n 
    INQUIRY: $inquiry \n 
    ";
    $from = "From: $visitormail\r\n";
    mail("sarahaustin@fuse.net", $subject, $message, $from);
    ?>
    <div id="leftColumn">
    <div class="text">
    <h3>Your Message Has Been Submitted!</h3>
    <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>
    <p>Have a great day!</p>
    </div>
    <div style="clear: both"></div>
    <p><span class="redText"><strong>Notice</strong></span><br />
    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>
    <h2><br />
    Recent Projects<br />
    </h2>
    <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>
    <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>
    <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>
    </div>
    <div id="rightColumn">
    <span class="contactFormTitle">Get in Touch</span><br />
    <p><script type="text/javascript">
    /*<![CDATA[*/
    /***********************************************
    * http://www.dynamicdrive.com/emailriddler/
    * **********************************************/
    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]
    var encryptedemail_id38='' //variable to contain encrypted email 
    for (var i=0; i<emailriddlerarray.length; i++)
    encryptedemail_id38+=String.fromCharCode(emailriddlerarray[i])
    document.write('<a href="mailto:'+encryptedemail_id38+'?subject=Message from Website"><img src="images/phone-email.gif" alt="Email Us" title="Email Us"/></a>')
    /*]]>*/
    </script></p>
    <div id="contact-form">
    <form action="mcd0310.php" method="post" onsubmit="MM_validateForm('visitor','','R','visitormail','','RisEmail','inquiry','','R');return document.MM_returnValue" ><?php
    $ipi = getenv("REMOTE_ADDR");
    $httprefi = getenv ("HTTP_REFERER");
    $httpagenti = getenv ("HTTP_USER_AGENT");
    ?>
    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
    Name: (Required)<br />
    <input name="Name" type="text" class="contact-fields" id="visitor" size="50" /><br />
    Email: (Required)<br />
    <input name="Email" type="text" class="contact-fields" id="visitormail" size="50" /><br />
    Company/Organization:<br />
    <input name="Company" type="text" class="contact-fields" id="company" size="50" /><br />
    Message: (Required)<br />
    <textarea name="Message" cols="1" rows="4" class="contact-multiline" id="inquiry"></textarea>
    <br />
    <br />
    <input type="submit" value="Submit Form" />
    </form>
    </div>
    </div>
    </div>
    </div>
    <!-- End right-column -->
    <div style="clear: both"></div>
    <div id="footerContainer">
    <div id="footerLeft"><img src="images/footer.gif" alt="" width="304" height="34" border="0" usemap="#Map" />
    <map name="Map" id="Map">
    <area shape="rect" coords="15,-3,151,37" href="http://www.mouseclickdesigns.com" alt="Mouse Click Designs" title="Mouse Click Designs" />
    <area shape="rect" coords="233,-4,307,38" href="http://twitter.com/mousetweets" alt="Follow MCD on Twitter" title="Follow MCD on Twitter" />
    <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" />
    </map></div>
    </div>
    </body>
    </html>
  • Sudaraka
    New Member
    • Jan 2011
    • 55

    #2
    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...
    Code:
    if(isset($_POST['Message'])) {
    //Send email
    }
    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)

    Comment

    • Austin Webb
      New Member
      • Mar 2011
      • 3

      #3
      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?

      Comment

      • Sudaraka
        New Member
        • Jan 2011
        • 55

        #4
        Try adding an echo() just before the mail() to see if the execution reach that in a situation you don't want it to.

        Comment

        • Austin Webb
          New Member
          • Mar 2011
          • 3

          #5
          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?

          Comment

          • dgreenhouse
            Recognized Expert Contributor
            • May 2008
            • 250

            #6
            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.

            Comment

            Working...