Announcement

Collapse
No announcement yet.

Having a problem that i shouldn't be...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Having a problem that i shouldn't be...

    Ok im in the process of writing my new site. Im moving away from my existing Joomla setup to a purely HTML/CSS based site (more for speed and the fact im fed up of the bloat that you get with Joomla).

    Now, im trying to write in a simple Contact Us form, and at the moment im using the following:

    On page code:
    Code:
    <form method="POST" action="contact.php">
    Fields marked (*) are required
    
    <p>Email From:* <br>
    <input type="text" name="EmailFrom">
    <p>Name:<br>
    <input type="text" name="Name">
    <p>Telephone:<br>
    <input type="text" name="Telephone">
    <p>Message:<br>
    <textarea name="Message"></textarea>
    <p><input type="submit" name="submit" value="Submit">
    </form>
    and i have the following code in the contact.php file:

    Code:
    <?php
    
    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
    $EmailTo = "sales@**********.com";
    $Subject = "You have a query from your site.";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Address = Trim(stripslashes($_POST['Address'])); 
    $Telephone = Trim(stripslashes($_POST['Telephone'])); 
    $Message = Trim(stripslashes($_POST['Message'])); 
    
    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Telephone: ";
    $Body .= $Telephone;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>
    But when i enter information in all of the fields and click submit, it takes me to the client login page at scenter.com and i gat a mail delivery failiure in the sending contact's inbox.

    Can anyone give me any pointers on what i am am doing wrong (i can't see why it isn't working haha)

  • #2
    I PM'ed a link over to you, it gets blocked on here for moderation and you get halve a dozen replies before you see it.

    Comment


    • #3
      Hi,
      I've tested with your script and it works fine with me, although our scripts are a bit differences.
      I had similar issue for my few other contact form php scripts before, after i contacted with tech support, they told only the mailbox created in the CP able to receive the email.
      Try to change your email to the mailbox in your CP and set forward.
      If still not working in your side, then you might try my form.
      Beside that, I found you have an extra unused command "$Address = Trim(stripslashes($_POST['Address'])); ". However, it works for me even it's present.


      <?php

      // ------------- CONFIGURABLE SECTION ------------------------

      $mailto = 'sales@***xx.com' ;

      $formurl = "form url" ;
      $errorurl = "error url" ;
      $thankyouurl = "thank you url" ;

      $email_is_required = 1;
      $name_is_required = 1;
      $uself = 1;
      $use_envsender = 1;
      $use_webmaster_email_for_from = 1;
      $use_utf8 = 1;

      // -------------------- END OF CONFIGURABLE SECTION ---------------

      $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n"

      ;
      $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ?

      'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-

      Type: text/plain; charset="utf-8"' ;
      if (!isset( $use_envsender )) { $use_envsender = 0 ; }
      $envsender = "-f$mailto" ;
      $subject = "You have a query from your site." ;
      $name = $_POST['name'] ;
      $email = $_POST['email'] ;
      $telephone = $_POST['telephone'] ;
      $message = $_POST['message'] ;
      $http_referrer = getenv( "HTTP_REFERER" );

      if (!isset($_POST['email'])) {
      header( "Location: $formurl" );
      exit ;
      }
      if (($email_is_required && (empty($email) || !ereg("@",

      $email))) || ($name_is_required && empty($name))) {
      header( "Location: $errorurl" );
      exit ;
      }
      if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
      header( "Location: $errorurl" );
      exit ;
      }
      if (empty($email)) {
      $email = $mailto ;
      }
      $fromemail = (!isset( $use_webmaster_email_for_from ) ||

      ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;

      if (get_magic_quotes_gpc()) {
      $comments = stripslashes( $comments );
      }

      $messageproper =
      "This message was sent from:\n" .
      "$http_referrer\n" .
      "------------------------------------------------------------\n" .
      "Name of sender: $name\n" .
      "Email of sender: $email\n" .
      "Telephone of sender: $telephone\n" .
      "------------------------- COMMENTS -------------------------\n\n" .
      $message .
      "\n\n------------------------------------------------------------\n" ;

      $headers =
      "From: \"$name\" <$fromemail>" . $headersep . "Reply-To:

      \"$name\" <$email>" . $headersep . "X-Mailer: chcs.php

      2.13.0" .
      $headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

      if ($use_envsender) {
      mail($mailto, $subject, $messageproper, $headers, $envsender );
      }
      else {
      mail($mailto, $subject, $messageproper, $headers );
      }
      header( "Location: $thankyouurl" );
      exit ;

      ?>

      Comment


      • #4
        Thanks for testing it, the only glitch I can think of as to why it isn't working is because the bulk of the site is held at domain.com/static/ while I put the site together, and it could bee looking in the domain root for what to do.

        I'll try changing the index name for the new site and move it over to the root directory and see if that's causing the problem.

        Tried moving it overto my .net tld for the same site address and im still getting the same issue.

        I'll give your form a whirl and see how it turns out
        Last edited by Chameleon; 19-11-2009, 01:39 AM.

        Comment


        • #5
          Just a quick post to let everyone know that i have resolved this issue.

          It still doesn't seem to be sending to my primary address as it isn't managed on my hosting account, but it was a simple matter of creating an address that was, and autoforwarding that address to my main one.

          Just to help out anyone who gets stuck on this in the future:

          here's the form code on the front end:

          Code:
          <h1><b>Contact us</b></h1>
          <hr>
          <form method="POST" action="thanks.php">
          <p>Name: <input type="text" name="name" size="20"></p>
          <p>Email: <input type="text" name="email" size="20"></p>
          <p>Subject: <input type="text" name="subject" size="20"></p>
          <p>Message:</p>
          <p><textarea rows="10" name="message" cols="42"></textarea></p>
          <p><input type="submit" value="Submit" name="B1"></p>
          </form>
          and here's the backend file thanks.php:

          Code:
          //place this at the top of your php file
          <?php
          
          $ToAddress = "sales@yourdomain.com";
          
          $message  = "Query from yourdomain.com\n";
          $message .= "-------------------------------------------\n";
          foreach ($_POST as $key => $value){$message .= "$key: $value\n";}
          $message .= "-------------------------------------------\n";
          
          mail("$ToAddress",
                 "Query from yourdomain.com",
                  "\r\n".$message,
                  "From: $ToAddress\r\nCc:\r\nBcc:\r\n\r\n");
          
          
          ?>
          
          
          //this is the start of the main page layout
          
          
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
          <head>
          <title>Your Name - Contact Us</title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <meta http-equiv="Content-Style-Type" content="text/css" />
          <link href="style.css" rel="stylesheet" type="text/css" />
          <link href="layout.css" rel="stylesheet" type="text/css" />
          <script src="js/cufon-yui.js" type="text/javascript"></script>
          <script src="js/cufon-replace.js" type="text/javascript"></script>
          <script src="js/Futura_Md_BT_italic_400.font.js" type="text/javascript"></script>
          <script src="js/Futura_Md_BT_italic_700.font.js" type="text/javascript"></script>
          <!--[if lt IE 7]>
          	<link href="ie_style.css" rel="stylesheet" type="text/css" />
          <![endif]-->
          </head>
          
          <body id="page3">
             <!-- header -->
             <div id="header">
             	<div class="row-1">
                	<div class="container">
                   	<div class="logo"><a href="index.html"><img alt="" src="images/logo.jpg" /></a></div>
                      <ul class="nav">
                      	<li><a href="index.html">Home</a>|</li>
                         <li><a href="#">This</a>|</li>
                         <li><a href="#">is</a>|</li>
                         <li><a href="#">the</a>|</li>
                         <li><a href="#">top</a>|</li>
                         <li><a href="#">menu</a>|</li>
                      </ul>
                   </div>
                </div>
             </div>
             <!-- content -->
             <div id="content">
             	<div class="row-1">
                	<div class="container">
          <h1><b>Contact us</b></h1>
          <hr>
          
          <p><b>We've received your message, We will contact you as soon as possible.</b></p>
          
               </div>
                </div>
             </div>
             <!-- footer -->
             <div id="footer">
             	<div class="container">
                	YourDomain &copy; 2010&nbsp; &nbsp; <a href="index-2.html">Privacy Policy</a>
                </div>
             </div>
             <script type="text/javascript"> Cufon.now(); </script>
          </body>
          </html>
          Thanks to wjleong and The Loon for their advice, much appreciated guys
          Last edited by Chameleon; 19-11-2009, 04:29 AM.

          Comment


          • #6
            Yep, I had the same problem in the past and resolved it the same way by creating an email address to send it to and then forwarding it. I believe it has something to do with the server set up to prevent someone using a form for spamming.

            Comment

            Working...
            X