SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 51
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Whats wrong with this code!

    Hi Guys,

    I'm no expert with this but I have the code below to fill in an enquiry form & send an E-mail but its not working. Only two fields are required (the name & E-mail address) but each time I get the error message There was a problem with sending the form. Please check to ensure you have filled in all the fields.

    I'm guessing it must be something in the first part but I cannot get it to work, - any ideas?

    PHP Code:
    <?php

    $SENT 
    false;
    if (
    $_POST && $_POST["name"] && eregi("^[a-zA-Z0-9 ]+$"$_POST["name"]) && $_POST["email"] && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$_POST["email"])) {

        
    $recipient "me@mydomain.com";
        
    $recipient "enquiries@mydomain.com";
        
    $subject "Enquiry from the Website";
        
    $email_header "From: " .$_POST["email"]. " (" .$_POST["name"]. ")\r\n";
            
    "Reply-To: " .$_POST["email"]. "";

        
    // build the email
        
    $s "The following contact form has been submitted:\n\n";

        
    $s .= "=== Customer Details =====\n";
        
    $s .= "Name: " .$_POST["name"]. "\n";
        
    $s .= "Company: " .$_POST["company"]. "\n";
        
    $s .= "Telephone: " .$_POST["telephone"]. "\n";
        
    $s .= "Email Address: " .$_POST["email"]. "\n\n";

        
    $s .= "=== Enquiry Information =====\n";
        
    $s .= trim($_POST["comments"])."\n\n";

        
    $s.= "Generated: " .date("Y-m-d H:i:s");

        
    $email wordwrap($s72). "\n\n\n"// wrap text to 72 characters

        
    if (@mail($recipient$subject$email$email_header)) {
            
    $SENT true;
        } else {
            
    $SENT false;
        }
    }

    ?>


    \\Rest of HTML code here...


    <? if (!$SENT) { ?>

                <? if (!$SENT && $_POST) { ?>
                    <p class="red">There was a problem with sending the form.<br />Please check to ensure you have filled in all the fields.</p>
                <? ?>
                <p><b>Enquiry Form</b><br />
                <span class="red">**</span> Indicates required fields</p>
                
                <form name="contact" action="contact.php" method="post">
                <fieldset class="conform">
                <legend>Your Details</legend><br />
                <label for="name">Name</label>
                <input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST["name"] : '' ?>" name="name" /> <span class="red">**</span><br />
                <label for="company">Company</label>
                <input id="company" type="text" size="40" value="<?php  echo (isset($_POST["company"])) ? $_POST["company"] : '' ?>" name="company" /><br />
                <label for="telephone">Telephone</label>
                <input id="telephone" type="text" size="40" value="<?php echo  (isset($_POST["telephone"])) ? $_POST["telephone"] : ''?>" name="telephone" /><br />
                <label for="email">Email Address</label>
                <input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : ''?>" name="email" /> <span class="red">**</span><br />
                </fieldset>

                <fieldset class="conform2">
                <legend>Further Information</legend><br />
                <textarea id="comments" name="comments" size="40" rows="8" cols="50"><?php  echo(isset($_POST["comments"])) ? $_POST["comments"] : '' ?></textarea>
                </fieldset>

                <br />
                <a href="javascript:document.contact.submit();"><img title="" height="43" alt="" src="images/submit.gif" width="102" border="0" /></a>
                </form>
                </div>

                <?
                    
    } else {
                
    ?>
                <p>Thank you for your enquiry. We will reply as soon as possible.</p>
                <?
                    
    }
                
    ?>
    Last edited by cpradio; Apr 16, 2013 at 08:26. Reason: Added php tags

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem is:
    PHP Code:
    <? if (!$SENT && $_POST) { ?>
    <p class="red">There was a problem with sending the form.<br />
    Please check to ensure you have filled in all the fields.</p>
    <? ?>
    No matter what the if clause returns, the code exits php, prints the html and returns to php.

    The solution is:
    PHP Code:
    <?php if (!$SENT && $_POST) {
        echo 
    '<p class="red">There was a problem with sending the form.<br />
        Please check to ensure you have filled in all the fields.</p>'
    ;
    ?>
    Denny Schlesinger
    web services

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply, - I have made the changes as you suggest but am still getting the same error! Any other ideas? thanks

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lee_sov View Post
    Thanks for your reply, - I have made the changes as you suggest but am still getting the same error! Any other ideas? thanks
    Put var_dump($SENT, $_POST); right above your if statement (inside PHP tags) and tell us what that outputs.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lee_sov View Post
    Thanks for your reply, - I have made the changes as you suggest but am still getting the same error! Any other ideas? thanks
    When do you get the error? On entry? After submitting the form?

    What I changed solved the problem on first entry but there can be other bugs in the code. One has to be methodical looking for bugs. For example, do you know what the form returns? Probably not but you could find out by adding a
    PHP Code:
    print_r($_POST); 
    or
    PHP Code:
    var_dump($_POST); 
    statement to the top of the action page. Only by examining the evidence can you clear up the mystery.
    Denny Schlesinger
    web services

  6. #6
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I get the error after submitting the form, i.e. fill in the details, press submit & then receive the 'There was a problem with sending the form.
    Please check to ensure you have filled in all the fields.' error message. Whatever I seem to change this message is always returned!

    Putting that code in at the top seemed to return NULL array(0) { } or bool(false) array(0) { }

    No idea what this means! any ideas? thanks

  7. #7
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Also receiving this:

    NULL array(5) { ["name"]=> string(9) "test name" ["company"]=> string(12) "test company" ["telephone"]=> string(11) "01234567890" ["email"]=> string(15) "me@mydomain.com" ["comments"]=> string(5) "test " }

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Okay, $SENT is always NULL. So we need to determine why that is. Is there more code that you are not showing us? Is all of this code in the same file (contact.php)?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #9
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    contact.php1.txtOk this is the whole of the Contact.php file. There was more code that I removed (HTML) but here is all of it - ive just removed names:

  10. #10
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Okay, $SENT is always NULL. So we need to determine why that is. Is there more code that you are not showing us? Is all of this code in the same file (contact.php)?
    The problem is the short php tags. Look what the browser sees:

    HTML Code:
    \\Rest of HTML code here...
    
    
    <? if (!$SENT) { ?>
    
                <? if (!$SENT && $_POST) { ?>
                    <p class="red">There was a problem with sending the form.<br />Please check to ensure you have filled in all the fields.</p>
                <? } ?>
                <p><b>Enquiry Form</b><br />
                <span class="red">**</span> Indicates required fields</p>
                
                <form name="contact" action="form.php" method="post">
                <fieldset class="conform">
                <legend>Your Details</legend><br />
                <label for="name">Name</label>
                <input id="name" type="text" size="40" value="" name="name" /> <span class="red">**</span><br />
                <label for="company">Company</label>
                <input id="company" type="text" size="40" value="" name="company" /><br />
                <label for="telephone">Telephone</label>
                <input id="telephone" type="text" size="40" value="" name="telephone" /><br />
                <label for="email">Email Address</label>
                <input id="email" type="text" size="40" value="" name="email" /> <span class="red">**</span><br />
                </fieldset>
    
                <fieldset class="conform2">
                <legend>Further Information</legend><br />
                <textarea id="comments" name="comments" size="40" rows="8" cols="50"></textarea>
                </fieldset>
    
                <br />
                <a href="javascript:document.contact.submit();"><img title="" height="43" alt="" src="images/submit.gif" width="102" border="0" /></a>
                </form>
                </div>
    
                <?
                    } else {
                ?>
                <p>Thank you for your enquiry. We will reply as soon as possible.</p>
                <?
                    }
                ?>
    Denny Schlesinger
    web services

  11. #11
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So is that the <? an ?> ? What do I need to do, change all of these? And to what <?php?

  12. #12
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    @captainccs ; Not really. If the server is setup to support short tags, the code works fine (I tested it locally, and it worked fine)...

    @lee_sov ; Check that your server is setup to use the short tags for PHP (the <?), other wise convert all <? to be <?php and see if it works.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  13. #13
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    Try this simplified version that has been tested:
    1. then add the clever bits one at a time:
    2. remove debug stuff when everything is working to your satisfaction


    PHP Code:
    <?php 
        
    // REM NEXT LINE TO RESET _POST
        
    $_POST = array();
    ?>
    <!doctype html>
    <head>
        <title>fred</title>
        <style type='text/css'>
        label {display:inline-block; width:6em; text-align:right; padding:0.42em 1em 0;}
        </style>
    </head>
    <body>    
    <?php
    error_reporting
    (-1);ini_set('display_errors',1);
    echo 
    '<pre>';
      
    print_r($_POST); // var_dump($_POST_);
    echo '</pre>';

    $SENT false;
    if (
        
    $_POST 
        
    && $_POST["name"
        && 
    $_POST["email"
        
    #&& eregi("^[a-zA-Z0-9 ]+$", $_POST["name"]) 
        #&& eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST["email"])
        
    )
    {
        
    $recipient      "me@mydomain.com";
        
    $recipient      "enquiries@mydomain.com";
        
    $subject        "Enquiry from the Website";
        
    $email_header   "From: " .$_POST["email"]
                        .    
    " ("  .$_POST["name"]. ")\r\n"
                        
    "Reply-To: " 
                        
    .   $_POST["email"]. "";

        
    // build the email
        
    $s  "The following contact form has been submitted:\n\n";
        
    $s .= "=== Customer Details =====\n";
        
    $s .= "Name: "          .$_POST["name"]     . "\n";
        
    $s .= "Company: "       .$_POST["company"]  . "\n";
        
    $s .= "Telephone: "     .$_POST["telephone"]. "\n";
        
    $s .= "Email Address: " .$_POST["email"]    . "\n\n";
        
    $s .= "=== Enquiry Information =====\n";
        
    $s .= trim($_POST["comments"])."\n\n";
        
    $s .= "Generated: " .date("Y-m-d H:i:s");

        
    $email wordwrap($s72). "\n\n\n"// wrap text to 72 characters

        
    if (@mail($recipient$subject$email$email_header)) {
            
    $SENT true;
        } else {
            
    $SENT false;
        }
    }

    //Rest of HTML code here...
    if (!$SENT) { ?>

        <?php if (!$SENT && $_POST) { ?>
        <p class="red">There was a problem with sending the form.
            <br />
            Please check to ensure you have filled in all the fields.
        </p>
        <?php ?>

        <p><b>Enquiry Form</b><br />
        <span class="red">**</span> Indicates required fields</p>

        <form name="contact" action="contact.php" method="post">
            <fieldset class="conform">
            <legend>Your Details</legend><br />
            <label for="name">Name</label>
            <input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST["name"] : '' ?>" name="name" /> <span class="red">**</span><br />
            <label for="company">Company</label>
            <input id="company" type="text" size="40" value="<?php  echo (isset($_POST["company"])) ? $_POST["company"] : '' ?>" name="company" /><br />
            <label for="telephone">Telephone</label>
            <input id="telephone" type="text" size="40" value="<?php echo  (isset($_POST["telephone"])) ? $_POST["telephone"] : ''?>" name="telephone" /><br />
            <label for="email">Email Address</label>
            <input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : ''?>" name="email" /> <span class="red">**</span><br />
            </fieldset>

            <fieldset class="conform2">
            <legend>Further Information</legend><br />
            <!-- REMOVED  size="40" -->
            <textarea id="comments" name="comments" rows="8" cols="50">
                <?php  echo(isset($_POST["comments"])) ? $_POST["comments"] : '' ?>
            </textarea>

            <br />
            <a href="javascript:document.contact.submit();">
                <img title="" height="43" alt="" src="images/submit.gif" width="102" />
            </a>
            <input type="submit" value="Submit" />
        </fieldset>
      </form>

      <?php } else { ?>
          <p>Thank you for your enquiry. We will reply as soon as possible.</p>
      <?php ?>
    </body>
    </html>
    Last edited by John_Betong; Apr 17, 2013 at 05:21. Reason: removed size='40' so that script validates

  14. #14
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The code worked for me as soon as I switched to long php tags. While short tags can be enabled it's a safer bet to use long tags. If the code gets moved to a different server it might break again.

    Long tags: <?php your code ?>
    Denny Schlesinger
    web services

  15. #15
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Also eregi is deprecated so you should use preg_match

    PHP Code:
    if ($_POST && $_POST["name"] && eregi("^[a-zA-Z0-9 ]+$"$_POST["name"]) && $_POST["email"] && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$_POST["email"])) { 
    would become

    PHP Code:
    if ($_POST && $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i"$_POST["name"]) && $_POST["email"] && preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"$_POST["email"])) { 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  16. #16
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Also eregi is deprecated so you should use preg_match
    There are other things than can be improved in that script:

    Better error reporting (specify the problem)
    Eliminate the Javascript submit and use a regular submit type input
    Denny Schlesinger
    web services

  17. #17
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok so I've changed all short tags to long & used preg_match instead of eregi, - still no change!!

    could this be some kind of server/host issue why its not working?

  18. #18
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Works fine for me. Make sure you fill out the name and e-mail address correctly.

    PHP Code:
    <?php

    $SENT 
    false;
    if (
    $_POST && $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i"$_POST["name"]) && $_POST["email"] && preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"$_POST["email"])) {

        
    $recipient "test@.co.uk";
        
    $recipient "enquiries@.co.uk";
        
    $subject "Enquiry from the  Website";
        
    $email_header "From: " .$_POST["email"]. " (" .$_POST["name"]. ")\r\n".
            
    "Reply-To: " .$_POST["email"]. "";

        
    // build the email
        
    $s "The following contact form has been submitted:\n\n";

        
    $s .= "=== Customer Details =====\n";
        
    $s .= "Name: " .$_POST["name"]. "\n";
        
    $s .= "Company: " .$_POST["company"]. "\n";
        
    $s .= "Telephone: " .$_POST["telephone"]. "\n";
        
    $s .= "Email Address: " .$_POST["email"]. "\n\n";

        
    $s .= "=== Enquiry Information =====\n";
        
    $s .= trim($_POST["comments"])."\n\n";

        
    $s.= "Generated: " .date("Y-m-d H:i:s");

        
    $email wordwrap($s72). "\n\n\n"// wrap text to 72 characters

        
    if (@mail($recipient$subject$email$email_header)) {
            
    $SENT true;
        } else {
            
    $SENT false;
        }
    }

    ?>

    <!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" lang="en">

    <head>
        <title></title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta http-equiv="imagetoolbar" content="no" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <meta name="revisit-after" content="7 days">
        <meta name="Copyright" content="Beverley Morris">
        <meta name="Robots" content="all">
        <meta name="language" content="en">
        <meta name="distribution" content="Global">

        <link rel="shortcut icon" href="/favicon.ico" />
        <link rel="stylesheet" type="text/css" href="css/print.css" media="print" />

        <style type="text/css" media="screen">
        <!--
        @import url(css/styles.css);
        -->
        </style>
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script> 
        <script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
         <script src="js/global.js" type="text/javascript"></script>
        <script src="js/jquery.goomaps.js" type="text/javascript"></script>
        
        
        
        
    </head>

    <body>

    <div id="container_header">
        <div id="header">

        <div id="logo"><h1><a href="/" title="Home"><span></span></a></h1></div>

        <div id="header-right">
        <div id="contact">
        Tel: 020   Fax: 020 <br />
        Email: <a href="mailto:enquiries@.co.uk">enquiries@.co.uk</a>
        </div>
        </div>

        <div id="navigation">
            <ul class="navInner">
                <li><a href="/">Homepage</a></li>
                <li><a href="about-us.htm" >About Us</a></li>
                <li>
                    <a href="our-services.htm">Our Services</a>
                    <ul>
                        
                    </ul>
                </li>
                <li>
                    <a href="team-profiles.htm" >Team Profiles</a>
                    <ul>
                        
                    </ul>
                </li>

            <li><a href="contact.php" class="active">Contact Us</a></li>
            </ul>
        </div>

        </div>
    </div>
        
    <div id="container_body">
        <div id="body">
            
            <div class="clearboth">&nbsp;</div>


            <div id="home_panel">

                <div id="home_bottompanel_content">

                <h2>Contact Us</h2>
            
                <div class="goomapsWrapper">
                    <h3>Office</h3>
                    <p>
                        <br />
                        <br />
                        <span>T:</span> +44 020 <br />
                        <span>F:</span> +44 020 <br />
                        <span>DX:</span> <br />
                        <span>E:</span> <a href="mailto:enquiries@.co.uk">enquiries@.co.uk</a>
                        
                    </p>    
                    <div id="map_canvas" class="map_canvas"></div>    
                </div>
                <div class="goomapsWrapper">
                    <h3>Office</h3>
                    <p>

                        <br />
                        <br />
                        <span>E:</span> <a href="mailto:.co.uk">.co.uk</a>
                    </p>                    
                    <div id="map_canvas2" class="map_canvas"></div>                    
                </div>            

                <div>
                <?php if (!$SENT) { ?>

                <?php if (!$SENT && $_POST) { 
                    echo 
    '<p class="red">There was a problem with sending the form.<br />Please check to ensure you have filled in all the fields.</p>';
                } 
    ?>
                <p><b>Enquiry Form</b><br />
                <span class="red">**</span> Indicates required fields</p>
                
                <form name="contact" action="contact.php" method="post">
                <fieldset class="conform">
                <legend>Your Details</legend><br />
                <label for="name">Name</label>
                <input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST["name"] : '' ?>" name="name" /> <span class="red">**</span><br />
                <label for="company">Company</label>
                <input id="company" type="text" size="40" value="<?php  echo (isset($_POST["company"])) ? $_POST["company"] : '' ?>" name="company" /><br />
                <label for="telephone">Telephone</label>
                <input id="telephone" type="text" size="40" value="<?php echo  (isset($_POST["telephone"])) ? $_POST["telephone"] : ''?>" name="telephone" /><br />
                <label for="email">Email Address</label>
                <input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : ''?>" name="email" /> <span class="red">**</span><br />
                </fieldset>

                <fieldset class="conform2">
                <legend>Further Information</legend><br />
                <textarea id="comments" name="comments" size="40" rows="8" cols="50"><?php  echo(isset($_POST["comments"])) ? $_POST["comments"] : '' ?></textarea>
                </fieldset>

                <br />
                <a href="javascript:document.contact.submit();"><img title="" height="43" alt="" src="images/submit.gif" width="102" border="0" /></a>
                </form>
                </div>

                <?php
                    
    } else {
                
    ?>
                <p>Thank you for your enquiry. We will reply as soon as possible.</p>
                <?php
                    
    }
                
    ?>

            </p>

                </div>
            </div>
            
            <div id="ftr">
            <span id="copyright">Copyright &copy; <br />
            Tel: 020 8852 4433 &nbsp;  Fax: 020 8463 9494 &nbsp; Email: <a href="mailto:enquiries@b.co.uk">enquiries@.co.uk</a></span>
            <span id="ftr_links"><a href="terms.htm">Terms of Use</a> <a href="privacy.htm">Privacy Policy</a> <a href="http://www..co.uk" title="Cambridge Web Design and Development by" target="_blank" class="last">Web Design by </a></span>
            <div class="clearboth">&nbsp;</div>
            </div>
            
        </div>

         <script>
             $(document).ready(function(){
             $('#map_canvas').goomaps("init", { 
                center: [51.467434,0.008308],
                zoom: 16,
                    clickable: true,
                    draggable: true,
                    scrollwheel: false,
                OverviewMapControlOptions: false,
             }).goomaps("addmarkers", [{ options: {
                    position: [51.467434,0.008308]

                    
                    
             }}]);
             $('#map_canvas2').goomaps("init", { 
                center: [51.462998,-0.010772],
                zoom: 16,
                    clickable: true,
                    draggable: true,
                    scrollwheel: false,
                OverviewMapControlOptions: false,
             }).goomaps("addmarkers", [{ options: {
                    position: [51.462998,-0.010772]

                    
             }}]);         
          });
         </script>

    </body>
    </html>
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  19. #19
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi guys, still cannot get this to work is there anything else I can try? The host has confirmed short tags are not supported so I've changed all to long tags & used preg_match rather than eregi but I'm still having the same error, - its like nothing I change makes any difference! Whatever I put in the form still returns the same error message & no E-mail is sent.

    The host has also said that sending out from the server requires SMTP authentication so I'm wondering if this could be the issue? They have sent me some example scripts of this but I've no idea how to implement it into my existing code!?

    What else can I do to test this or get it to work?

    Thanks

  20. #20
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Paste one of the sample scripts here. I'd need to see what they told you to be able to help you update your script.

    In the meantime, run this test:
    PHP Code:
    <?php

    $SENT 
    false;
    if (
    $_POST && $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i"$_POST["name"]) && $_POST["email"] && preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"$_POST["email"])) {

        
    $recipient "test@.co.uk";
        
    $recipient "enquiries@.co.uk";
        
    $subject "Enquiry from the  Website";
        
    $email_header "From: " .$_POST["email"]. " (" .$_POST["name"]. ")\r\n".
            
    "Reply-To: " .$_POST["email"]. "";

        
    // build the email
        
    $s "The following contact form has been submitted:\n\n";

        
    $s .= "=== Customer Details =====\n";
        
    $s .= "Name: " .$_POST["name"]. "\n";
        
    $s .= "Company: " .$_POST["company"]. "\n";
        
    $s .= "Telephone: " .$_POST["telephone"]. "\n";
        
    $s .= "Email Address: " .$_POST["email"]. "\n\n";

        
    $s .= "=== Enquiry Information =====\n";
        
    $s .= trim($_POST["comments"])."\n\n";

        
    $s.= "Generated: " .date("Y-m-d H:i:s");

        
    $email wordwrap($s72). "\n\n\n"// wrap text to 72 characters

        
    echo "Attempting to send e-mail...";
        if (@
    mail($recipient$subject$email$email_header)) {
            
    $SENT true;
            echo 
    "Success!";
        } else {
            
    $SENT false;
            echo 
    "Failed!";
        }
    }

    ?>

    <!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" lang="en">

    <head>
        <title></title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta http-equiv="imagetoolbar" content="no" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <meta name="revisit-after" content="7 days">
        <meta name="Copyright" content="Beverley Morris">
        <meta name="Robots" content="all">
        <meta name="language" content="en">
        <meta name="distribution" content="Global">

        <link rel="shortcut icon" href="/favicon.ico" />
        <link rel="stylesheet" type="text/css" href="css/print.css" media="print" />

        <style type="text/css" media="screen">
        <!--
        @import url(css/styles.css);
        -->
        </style>
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script> 
        <script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
         <script src="js/global.js" type="text/javascript"></script>
        <script src="js/jquery.goomaps.js" type="text/javascript"></script>
        
        
        
        
    </head>

    <body>

    <div id="container_header">
        <div id="header">

        <div id="logo"><h1><a href="/" title="Home"><span></span></a></h1></div>

        <div id="header-right">
        <div id="contact">
        Tel: 020   Fax: 020 <br />
        Email: <a href="mailto:enquiries@.co.uk">enquiries@.co.uk</a>
        </div>
        </div>

        <div id="navigation">
            <ul class="navInner">
                <li><a href="/">Homepage</a></li>
                <li><a href="about-us.htm" >About Us</a></li>
                <li>
                    <a href="our-services.htm">Our Services</a>
                    <ul>
                        
                    </ul>
                </li>
                <li>
                    <a href="team-profiles.htm" >Team Profiles</a>
                    <ul>
                        
                    </ul>
                </li>

            <li><a href="contact.php" class="active">Contact Us</a></li>
            </ul>
        </div>

        </div>
    </div>
        
    <div id="container_body">
        <div id="body">
            
            <div class="clearboth">&nbsp;</div>


            <div id="home_panel">

                <div id="home_bottompanel_content">

                <h2>Contact Us</h2>
            
                <div class="goomapsWrapper">
                    <h3>Office</h3>
                    <p>
                        <br />
                        <br />
                        <span>T:</span> +44 020 <br />
                        <span>F:</span> +44 020 <br />
                        <span>DX:</span> <br />
                        <span>E:</span> <a href="mailto:enquiries@.co.uk">enquiries@.co.uk</a>
                        
                    </p>    
                    <div id="map_canvas" class="map_canvas"></div>    
                </div>
                <div class="goomapsWrapper">
                    <h3>Office</h3>
                    <p>

                        <br />
                        <br />
                        <span>E:</span> <a href="mailto:.co.uk">.co.uk</a>
                    </p>                    
                    <div id="map_canvas2" class="map_canvas"></div>                    
                </div>            

                <div>
                <?php if (!$SENT) { ?>

                <?php if (!$SENT && $_POST) { 
                    echo 
    '<p class="red">There was a problem with sending the form.<br />Please check to ensure you have filled in all the fields.</p>';
                } 
    ?>
                <p><b>Enquiry Form</b><br />
                <span class="red">**</span> Indicates required fields</p>
                
                <form name="contact" action="contact.php" method="post">
                <fieldset class="conform">
                <legend>Your Details</legend><br />
                <label for="name">Name</label>
                <input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST["name"] : '' ?>" name="name" /> <span class="red">**</span><br />
                <label for="company">Company</label>
                <input id="company" type="text" size="40" value="<?php  echo (isset($_POST["company"])) ? $_POST["company"] : '' ?>" name="company" /><br />
                <label for="telephone">Telephone</label>
                <input id="telephone" type="text" size="40" value="<?php echo  (isset($_POST["telephone"])) ? $_POST["telephone"] : ''?>" name="telephone" /><br />
                <label for="email">Email Address</label>
                <input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : ''?>" name="email" /> <span class="red">**</span><br />
                </fieldset>

                <fieldset class="conform2">
                <legend>Further Information</legend><br />
                <textarea id="comments" name="comments" size="40" rows="8" cols="50"><?php  echo(isset($_POST["comments"])) ? $_POST["comments"] : '' ?></textarea>
                </fieldset>

                <br />
                <a href="javascript:document.contact.submit();"><img title="" height="43" alt="" src="images/submit.gif" width="102" border="0" /></a>
                </form>
                </div>

                <?php
                    
    } else {
                
    ?>
                <p>Thank you for your enquiry. We will reply as soon as possible.</p>
                <?php
                    
    }
                
    ?>

            </p>

                </div>
            </div>
            
            <div id="ftr">
            <span id="copyright">Copyright &copy; <br />
            Tel: 020 8852 4433 &nbsp;  Fax: 020 8463 9494 &nbsp; Email: <a href="mailto:enquiries@b.co.uk">enquiries@.co.uk</a></span>
            <span id="ftr_links"><a href="terms.htm">Terms of Use</a> <a href="privacy.htm">Privacy Policy</a> <a href="http://www..co.uk" title="Cambridge Web Design and Development by" target="_blank" class="last">Web Design by </a></span>
            <div class="clearboth">&nbsp;</div>
            </div>
            
        </div>

         <script>
             $(document).ready(function(){
             $('#map_canvas').goomaps("init", { 
                center: [51.467434,0.008308],
                zoom: 16,
                    clickable: true,
                    draggable: true,
                    scrollwheel: false,
                OverviewMapControlOptions: false,
             }).goomaps("addmarkers", [{ options: {
                    position: [51.467434,0.008308]

                    
                    
             }}]);
             $('#map_canvas2').goomaps("init", { 
                center: [51.462998,-0.010772],
                zoom: 16,
                    clickable: true,
                    draggable: true,
                    scrollwheel: false,
                OverviewMapControlOptions: false,
             }).goomaps("addmarkers", [{ options: {
                    position: [51.462998,-0.010772]

                    
             }}]);         
          });
         </script>

    </body>
    </html>
    After submitting the form (and if the name and e-mail are provided and valid), you should see "Attempting to send e-mail..." followed by Success! or Failed!. That way we at least know the issue is with sending the email and not your validation.

    Then once we have a sample, we can help you update your mail section so it works.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  21. #21
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok I've run that test, adding in the echo commands but its made no difference, - I still just receive the same message 'There was a problem with sending the form...' I don't understand why its not making any difference!

    This is the link they sent me with the example scripts: http://eurofasthost.com/support/know...email_SMTP.asp

    This is the example phpMailer one:

    Code:
    IsSMTP(); // set mailer to use SMTP $mail->Host = "mail.domain.com"; // specify main and backup server $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "outbound@domain.com"; // SMTP username $mail->Password = "password"; // SMTP password // Set Sender/Recipient $mail->From = "contactform@domain.com"; $mail->FromName = "From Name"; $mail->AddAddress("info@domain.com", "Domain name"); //Address of recipient // Build Message Body $msg = " Name: $name Email: $email Telephone: $telephone Message: $message "; // Set Subject + Body + Settings $mail->Subject = "Subject Title"; $mail->Body = $msg; $mail->WordWrap = 50; // set word wrap to 50 characters // Send Message and Report if(!$mail->Send()) { echo "Message could not be sent. 
    "; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Mail was sent thank you!"; echo sprintf("
    Go Back ",$_SERVER['HTTP_REFERER']); ?>
    Thanks

  22. #22
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    So you didn't get any additional verbiage at the top of the page after completing the form?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  23. #23
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No nothing additional, just the same error message as before...

  24. #24
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,814
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Okay, let's add a bit more debugging data, place this at the top of your script:

    PHP Code:
    if ($_POST) {
        if (
    $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i"$_POST["name"]) === false) {
          die(
    "failed to validate the name");
        }
        if (
    $_POST["email"] && preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"$_POST["email"]) === false) {
          die(
    "failed to validate the e-mail");
        }

    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  25. #25
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    it's still not changing anything! Am I doing something wrong here?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •