Need Help with Contact Form and Newsletter

  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 17th, 2011, 9:28 am

Brian,

I'm on a shared hosting server. I think what would be easier is if we were in a chat where by I can share my screen with you and then you can see all the information at once.

What do you think of that idea?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 17th, 2011, 9:28 am

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 17th, 2011, 9:37 am

Hi James,

I only do help like this via Ozzu as the information we discuss here will hopefully be able to resolve your problem, but also other people down the road as that other thread initially had helped you.

You are absolutely welcome to take screenshots and post them in this thread. You will find an attachment button in the advanced reply area.

Thanks for your understanding :)
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 17th, 2011, 9:37 am

no the message just sits in the outbox... I even read the PM faq on this forum.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 17th, 2011, 9:40 am

If it is in the Outbox, that simply means the other person has not read it yet. If it is in the Sentbox it means it has been read. The system should be working fine :)
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 17th, 2011, 11:40 am

Bigwebmaster wrote:
Please let me know what flavor of Linux you are running, ie Redhat, Debian, Ubuntu, etc. Please also let me know what version. Also please let me know what version of PHP you are running as if your version is outdated that could explain some of your problems. What version of Apache are you running? The more information you could tell me about your setup the better I can assist you. By the way, do you have root access to the server, or are you on shared hosting with a hosting company? Thanks!


The server is with Host Gator on shared hosting. I really wouldn't have thought this server cant handle a simple form to email procedure as it seems to handle a lot more complex scripts, which is why I'm leaning more towards I have something not right with the code either in the contact.php file (previously posted) or my HTML form (again previously posted).

Its gotta be something simple as I get the emails just no end user data in the email.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 17th, 2011, 2:41 pm

Most of the problems anybody experience are usually small things that are easily fixable. The problem is determining exactly what that problem is and that is where the more information you can tell me, the better I can diagnose and help you with the problem. For instance the version of PHP you are running is important, if you are running less than PHP 4.1 the $_POST variable isn't even supported yet:

http://php.net/manual/en/reserved.variables.post.php

I imagine your PHP version wouldn't be that old. You might contact your webhost to see if they can help diagnose your problem. Your script looks fine which indicates that it would be the server setup somehow. If you can run this script:

PHP Code: [ Select ]
<?php
phpinfo();
?>
  1. <?php
  2. phpinfo();
  3. ?>


That might tell you more information on how your server is setup, what version of PHP is being used, what functions are disallowed, etc. Some hosts might not let you run the phpinfo() function, not sure what hostgator does.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 18th, 2011, 6:28 am

Brian,

Please see the attached file. Like I said the server handles other configured forms in ready made scripts fine. I appreciate your time and effort on this and will let you know when I have resolved it and what I did.

Thanks.

James
Attachments:
Untitled.png

server info

  • garrett2828
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 18, 2011
  • Posts: 6
  • Status: Offline

Post October 18th, 2011, 8:29 am

hey Brian, James,
I am having the same exact problems just getting email back without any text of anything and my information is almost identical to his above! PLEASE help this has taken all my time for two days now! also how do you get the newsletter to work? i know people ask that but it keeps getting ignored... do you have a special php file for that? if so could you show/upload. thanks so much guys!
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 18th, 2011, 10:07 am

James - thanks for posting all of that information, that will help.

Garrett - I would be curious where you host your website?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 18th, 2011, 10:10 am

I looked up your PHP version with others having similar issues. Many mentioned that their rewrite rules were what ended up causing the problem for the $_POST variable being blank.

Could you do me a favor James and look to see if you have a .htaccess file in your root folder. If you do can you please copy and paste the contents of that file here?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 18th, 2011, 12:10 pm

Brian,

I got it working.....finally. Sorry but I dont have .htaccess file in root, so thinking whoever is having an issue like I was could maybe have some code wrong like I did....I knew it was coding. I've never had any issues like this before.

I will post how I fixed my issue next. Bare in mind I know one or two of you were looking for this to work with a newsletter and I'm sure this code can be tweaked to fit that as well, however I just wanted the form to be sent via email and I got my result.

Resolution code coming up next
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 18th, 2011, 12:17 pm

This is the code from my HTML form which is then linked to "contact.php"

Code: [ Select ]
<h2>Contact Form</h2>
                            <form method="POST" name="contact_form"
                            action="contact.php">
                            <p>
                            <label for='name'>Name: </label><br>
                            <input type="text" name="name">
                            </p>
                            <p>
                            <label for='email'>Email: </label><br>
                            <input type="text" name="email">
                            </p>
                            <p>
                            <label for='message'>Message:</label> <br>
                            <textarea name="message"></textarea>
                            </p>
                            <p>
                            <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
                            <label for='message'>Enter the code above here :</label><br>
                            <input id="6_letters_code" name="6_letters_code" type="text"><br>
                            <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
                            </p>
                            <input type="submit" value="Submit" name='submit'>
                            </form>
                            <script language="JavaScript">
                            // Code for validating the form
                            var frmvalidator = new Validator("contact_form");
                            //remove the following two lines if you like error message box popups
                            frmvalidator.EnableOnPageErrorDisplaySingleBox();
                            frmvalidator.EnableMsgsTogether();
                            
                            frmvalidator.addValidation("name","req","Please provide your name");
                            frmvalidator.addValidation("email","req","Please provide your email");
                            frmvalidator.addValidation("email","email","Please enter a valid email address");
                            </script>
                            <script language='JavaScript' type='text/javascript'>
                            function refreshCaptcha()
                            {
                                var img = document.images['captchaimg'];
                                img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
                            }
                            </script>
  1. <h2>Contact Form</h2>
  2.                             <form method="POST" name="contact_form"
  3.                             action="contact.php">
  4.                             <p>
  5.                             <label for='name'>Name: </label><br>
  6.                             <input type="text" name="name">
  7.                             </p>
  8.                             <p>
  9.                             <label for='email'>Email: </label><br>
  10.                             <input type="text" name="email">
  11.                             </p>
  12.                             <p>
  13.                             <label for='message'>Message:</label> <br>
  14.                             <textarea name="message"></textarea>
  15.                             </p>
  16.                             <p>
  17.                             <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
  18.                             <label for='message'>Enter the code above here :</label><br>
  19.                             <input id="6_letters_code" name="6_letters_code" type="text"><br>
  20.                             <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
  21.                             </p>
  22.                             <input type="submit" value="Submit" name='submit'>
  23.                             </form>
  24.                             <script language="JavaScript">
  25.                             // Code for validating the form
  26.                             var frmvalidator = new Validator("contact_form");
  27.                             //remove the following two lines if you like error message box popups
  28.                             frmvalidator.EnableOnPageErrorDisplaySingleBox();
  29.                             frmvalidator.EnableMsgsTogether();
  30.                             
  31.                             frmvalidator.addValidation("name","req","Please provide your name");
  32.                             frmvalidator.addValidation("email","req","Please provide your email");
  33.                             frmvalidator.addValidation("email","email","Please enter a valid email address");
  34.                             </script>
  35.                             <script language='JavaScript' type='text/javascript'>
  36.                             function refreshCaptcha()
  37.                             {
  38.                                 var img = document.images['captchaimg'];
  39.                                 img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
  40.                             }
  41.                             </script>


The following is the code from "contact.php"

Code: [ Select ]
<?php
$your_email ='';// <<=== update to your email address

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
    
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $user_message = $_POST['message'];
    ///------------Do Validations-------------
    if(empty($name)||empty($visitor_email))
    {
        $errors .= "\n Name and Email are required fields. ";    
    }
    if(IsInjected($visitor_email))
    {
        $errors .= "\n Bad email value!";
    }
    if(empty($_SESSION['6_letters_code'] ) ||
     strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
    {
    //Note: the captcha code is compared case insensitively.
    //if you want case sensitive match, update the check above to
    // strcmp()
        $errors .= "\n The captcha code does not match!";
    }
    
    if(empty($errors))
    {
        //send the email
        $to = $your_email;
        $subject="New form submission";
        $from = $your_email;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
        
        $body = "A user $name submitted the contact form:\n".
        "Name: $name\n".
        "Email: $visitor_email \n".
        "Message: \n ".
        "$user_message\n".
        "IP: $ip\n";    
        
        $headers = "From: $from \r\n";
        $headers .= "Reply-To: $visitor_email \r\n";
        
        mail($to, $subject, $body,$headers);
        
        header('Location: contacts.html');
    }
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
 $injections = array('(\n+)',
       '(\r+)',
       '(\t+)',
       '(%0A+)',
       '(%0D+)',
       '(%08+)',
       '(%09+)'
       );
 $inject = join('|', $injections);
 $inject = "/$inject/i";
 if(preg_match($inject,$str))
  {
  return true;
 }
 else
  {
  return false;
 }
}
?>
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
  1. <?php
  2. $your_email ='';// <<=== update to your email address
  3. session_start();
  4. $errors = '';
  5. $name = '';
  6. $visitor_email = '';
  7. $user_message = '';
  8. if(isset($_POST['submit']))
  9. {
  10.     
  11.     $name = $_POST['name'];
  12.     $visitor_email = $_POST['email'];
  13.     $user_message = $_POST['message'];
  14.     ///------------Do Validations-------------
  15.     if(empty($name)||empty($visitor_email))
  16.     {
  17.         $errors .= "\n Name and Email are required fields. ";    
  18.     }
  19.     if(IsInjected($visitor_email))
  20.     {
  21.         $errors .= "\n Bad email value!";
  22.     }
  23.     if(empty($_SESSION['6_letters_code'] ) ||
  24.      strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
  25.     {
  26.     //Note: the captcha code is compared case insensitively.
  27.     //if you want case sensitive match, update the check above to
  28.     // strcmp()
  29.         $errors .= "\n The captcha code does not match!";
  30.     }
  31.     
  32.     if(empty($errors))
  33.     {
  34.         //send the email
  35.         $to = $your_email;
  36.         $subject="New form submission";
  37.         $from = $your_email;
  38.         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
  39.         
  40.         $body = "A user $name submitted the contact form:\n".
  41.         "Name: $name\n".
  42.         "Email: $visitor_email \n".
  43.         "Message: \n ".
  44.         "$user_message\n".
  45.         "IP: $ip\n";    
  46.         
  47.         $headers = "From: $from \r\n";
  48.         $headers .= "Reply-To: $visitor_email \r\n";
  49.         
  50.         mail($to, $subject, $body,$headers);
  51.         
  52.         header('Location: contacts.html');
  53.     }
  54. }
  55. // Function to validate against any email injection attempts
  56. function IsInjected($str)
  57. {
  58.  $injections = array('(\n+)',
  59.        '(\r+)',
  60.        '(\t+)',
  61.        '(%0A+)',
  62.        '(%0D+)',
  63.        '(%08+)',
  64.        '(%09+)'
  65.        );
  66.  $inject = join('|', $injections);
  67.  $inject = "/$inject/i";
  68.  if(preg_match($inject,$str))
  69.   {
  70.   return true;
  71.  }
  72.  else
  73.   {
  74.   return false;
  75.  }
  76. }
  77. ?>
  78. <?php
  79. if(!empty($errors)){
  80. echo "<p class='err'>".nl2br($errors)."</p>";
  81. }
  82. ?>
  • garrett2828
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 18, 2011
  • Posts: 6
  • Status: Offline

Post October 18th, 2011, 12:50 pm

Hey i did all the above but i am having a problem with the captcha image, its not showing up on my page. did you have a problem with this?
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 18th, 2011, 12:54 pm

I'm not authorized to post URLs in here so PM me and I will give you the URL for where to get the captcha files for the images.
  • jharvey1029
  • Novice
  • Novice
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 18th, 2011, 1:09 pm

Guys,

attached is a zip file that gives you all that you need to make your form send to email. Please NOTE, this is NOT my work, I dont support any of it and I take NO RESPONSIBILITY for it or how you use it. I recommend you look through the files carefully and you can cut and paste the stuff you need from it to make your own files or use as is.

Good luck everyone and thanks to BigWebmaster for sticking with me.
Attachments:
html-contact-form-captcha.zip

(22.92 KiB) Downloaded 207 times

form w/captcha

  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 18th, 2011, 1:09 pm

Post Information

  • Total Posts in this topic: 51 posts
  • Users browsing this forum: No registered users and 91 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.