Need Help with Contact Form and Newsletter

  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

Hello Bigwebmaster and Everyone,

First off thanks for reading my message. I want to refer you all to the above mentioned where Bigwebmaster helped someone with a contact form HTML file and made adjustments to the code and created a contact.php file to make the form send email. I have a very similar HTML form/code however I tried to follow the same direction and have been stuck with getting blank emails. I was wondering if there was anyone kind enough to look through my HTML code and the contact.php file and help me get this corrected. I haven't attached any code etc in-case you want the whole file/s sent to an email address or whatever.

A very many thanks.

James
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Hi James, please post your code here, both the HTML and PHP file so that we can take a look.
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

this is the contact.php file

PHP Code: [ Select ]
<?php
    $field_name = $_POST['full_name'];
    $field_email = $_POST['email'];
   $field_email = $_POST['telephone'];
    $field_message = $_POST['message'];
     
    $mail_to = 'myemailaddress';
    $subject = 'Message from a site visitor '.$field_name;
     
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
   $body_message .= 'Telephone: '.$field_message;
    $body_message .= 'Message: '.$field_message;
     
    $headers = 'From: '.$email."\r\n";
    $headers .= 'Reply-To: '.$email."\r\n";
     
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
     
    if ($mail_status) { ?>
       <script language="javascript" type="text/javascript">
          alert('Thank you for the message. We will contact you shortly.');
          window.location = 'contacts.html';
       </script>
    <?php
    }
    else { ?>
       <script language="javascript" type="text/javascript">
          alert('Message failed. Please, send an email to myemailaddress');
          window.location = 'contacts.html';
       </script>
    <?php
    }
    ?>
  1. <?php
  2.     $field_name = $_POST['full_name'];
  3.     $field_email = $_POST['email'];
  4.    $field_email = $_POST['telephone'];
  5.     $field_message = $_POST['message'];
  6.      
  7.     $mail_to = 'myemailaddress';
  8.     $subject = 'Message from a site visitor '.$field_name;
  9.      
  10.     $body_message = 'From: '.$field_name."\n";
  11.     $body_message .= 'E-mail: '.$field_email."\n";
  12.    $body_message .= 'Telephone: '.$field_message;
  13.     $body_message .= 'Message: '.$field_message;
  14.      
  15.     $headers = 'From: '.$email."\r\n";
  16.     $headers .= 'Reply-To: '.$email."\r\n";
  17.      
  18.     $mail_status = mail($mail_to, $subject, $body_message, $headers);
  19.      
  20.     if ($mail_status) { ?>
  21.        <script language="javascript" type="text/javascript">
  22.           alert('Thank you for the message. We will contact you shortly.');
  23.           window.location = 'contacts.html';
  24.        </script>
  25.     <?php
  26.     }
  27.     else { ?>
  28.        <script language="javascript" type="text/javascript">
  29.           alert('Message failed. Please, send an email to myemailaddress');
  30.           window.location = 'contacts.html';
  31.        </script>
  32.     <?php
  33.     }
  34.     ?>


and the HTML file:

HTML Code: [ Select ]
<h2>Contact Form</h2>
                     <form id="contacts-form" action="contact.php" enctype="multipart/form-data">
                        <fieldset>
                           <div class="field text"><input name="full_name" id="full_name" input type"text" value="Your Name"></div>
                           <div class="field text"><input name="email" id="email" input type"text" value="Email"></div>
                           <div class="field text"><input name="telephone" id="telephone" input type="text" value="Telephone"></div>
                           <div class="field"><textarea name="message" id="message" onBlur="if(this.value=='')this.value="Enter Your Message:'" onFocus="if(this.value =='Enter your Message:' ) this.value=''" >Enter Your Message Here:</textarea></div>
                           <div class="alignright"><div class="alignright"><a href="#" class="link4" onClick="document.getElementById('contacts-form').reset()"><span><span>Clear</span></span></a><a href="contact.php" class="link2" onClick="document.getElementById('contacts-form').submit()"><span><span>Send</span></span></a></div>
                        </fieldset>
                     </form>
  1. <h2>Contact Form</h2>
  2.                      <form id="contacts-form" action="contact.php" enctype="multipart/form-data">
  3.                         <fieldset>
  4.                            <div class="field text"><input name="full_name" id="full_name" input type"text" value="Your Name"></div>
  5.                            <div class="field text"><input name="email" id="email" input type"text" value="Email"></div>
  6.                            <div class="field text"><input name="telephone" id="telephone" input type="text" value="Telephone"></div>
  7.                            <div class="field"><textarea name="message" id="message" onBlur="if(this.value=='')this.value="Enter Your Message:'" onFocus="if(this.value =='Enter your Message:' ) this.value=''" >Enter Your Message Here:</textarea></div>
  8.                            <div class="alignright"><div class="alignright"><a href="#" class="link4" onClick="document.getElementById('contacts-form').reset()"><span><span>Clear</span></span></a><a href="contact.php" class="link2" onClick="document.getElementById('contacts-form').submit()"><span><span>Send</span></span></a></div>
  9.                         </fieldset>
  10.                      </form>
Moderator Remark: Please remember to use [code][/code] around any code in your post to make it more readable. Thank you!
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Go ahead and remove enctype="multipart/form-data" in your HTML code above since you are not having them attach any files. See if that makes any difference in getting anything to work for you.

Also while this wouldn't cause any problems for making the above actually work, you are going to want to add in some sort of sanity checks on the code people enter in you form. If you do not do that you are going to find that spammers can eventually abuse your form to send out spam e-mail to others via your web server without you knowing.

Finally to clarify, you are getting e-mails sent to you right? They are just blank? Do they have subjects or is that blank too?
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

I am getting emails but the subject of the emails states unknown address. Which is very confusing.

I really want to get this working I know I am close to getting it working. I really appreciate you helping me with this.
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

I was also wondering if you had a little code that maybe I can enter for your suggestion: "you are going to want to add in some sort of sanity checks on the code people enter in you form"
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Could you let us know exactly what you receive, you mention that the subject says "Unknown Address". Is this all it says, please let us know exactly what it says word for word. The message part of the e-mail is blank correct?

As far as sanitizing your input, there are many ways. You might take a look at this:

http://www.php.net/manual/en/filter.exa ... dation.php
http://www.php.net/manual/en/function.filter-var.php

So in your above example for the code you posted, you would want to do some sort of validation for each bit of input you receive from your visitor. So take this part of your code:

PHP Code: [ Select ]
$field_email = $_POST['email'];


Instead of that you might do:

PHP Code: [ Select ]
        $field_email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {  
            echo "$email is a valid email address.";  
        } else {  
            echo "$email is <strong>NOT</strong> a valid email address.";  
        }
  1.         $field_email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
  2.         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {  
  3.             echo "$email is a valid email address.";  
  4.         } else {  
  5.             echo "$email is <strong>NOT</strong> a valid email address.";  
  6.         }


This would first sanitize your input, and then it would validate the e-mail to make sure its actually an e-mail address in a valid format. You can see all of the different types of filters here:

http://www.php.net/manual/en/filter.filters.php

So you can see that the FILTER_SANITIZE_EMAIL removes all characters except letters, digits and !#$%&'*+-/=?^_`{|}~@.[].
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

yeah sure. Basically when an email arrives I get the 4 labels:

Name
Email
Telephone
Message

thats it. There's no input data. Its like it cant see from where to get the information. However I get how it should and figured with how it was setup it should but nothing always is flawless...lol

btw I added you on twitter today and would like to talk to you about a business interest.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Your code seems correct to me. Do you know what version of PHP is running on your server? Is it a Windows or Linux server?

Feel free to PM me about your business interest.
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

I would PM you but it seems either I dont have PM rights or its off for everyone. I'll message you on twitter and give you my contact details.

As for PHP on the server its running 5.2.17 linux and I have to say I dont have any kind of issues with the server. This html code is part of a template downloaded from its creator and I'm simply editing it for my own use. (with permission of course, its one of those freebies)
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

Hey Brian, I made those adjustments but still I'm getting the same thing. An email with the subject "invalid address" and in the email I get just the headings "Name, Email, Telephone and Message" nothing as far as input data on the form.

Man I know we are so close I can feel it....lol Its gotta be something simple tho, I just cant see it
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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!
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

Here is an example of the email when I open it.


Date: Mon, 17 Oct 2011 10:13:07 -0500 [10:13:07 AM CDT]
From: Undisclosed Recipients
To: my email address


Subject: Message from a site visitor
From:
E-mail:
Telephone: Message:
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

this is before I have opened it.

10:13:07 AM Invalid Address Message from a site visitor
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

The PM system here should work, are you receiving some sort of error message?
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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 :)
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

no the message just sits in the outbox... I even read the PM faq on this forum.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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 :)
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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.
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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
  • garrett2828
  • Posts: 6

Post 3+ Months Ago

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
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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

Garrett - I would be curious where you host your website?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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?
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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
  • garrett2828
  • Posts: 6

Post 3+ Months Ago

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
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

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 344 times

form w/captcha

  • garrett2828
  • Newbie
  • Newbie
  • garrett2828
  • Posts: 6

Post 3+ Months Ago

thanks so much for everything guys...... Now do you think there is a way to make the newsletter task work?
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

you might want to look up the original posting with the same thread name as this and check out bigwebmaster's html code there.
  • garrett2828
  • Newbie
  • Newbie
  • garrett2828
  • Posts: 6

Post 3+ Months Ago

real quick..... how do i make the page route back to my home page etc. once you hit submit.... it is just taking me to a blank page with url as contact.php is there a way to change this? thanks
Garrett
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Glad you were able to get it to work with the new script James. Wish we could figure out what the actual problem was with your original script as that script still looks fine to me. I am sure there has to be some sort of logical problem to why it was not working. At least its working for you now!
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Garrett - in the contact.php code change this line:

PHP Code: [ Select ]
header('Location: contacts.html');


to something like:

PHP Code: [ Select ]
header('Location: http://www.yoursite.com/');


and it should redirect you to your main site page instead.
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

Brian,

was more to do with the php file than anything. Just not configured correctly.

I do have one thing you might be able to help with:

If I use the following: <input type="submit" value="Submit" name='submit'> the form submits redirects back to its original page (as directed to) and the email and EU data is received in email as planned.

However I dont like that grey boring submit button and want to use the buttons that you see on the page as of now. (will PM you a link to this page) only I cant seem to get the form to submit when the EU clicks "Send". It appears begins to process the php file but then stops and all I get is a blank screen.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

It is not working because it is expecting the "submit" variable to be passed which it is no longer doing. Somewhere before the submit button you could add this to override that:

HTML Code: [ Select ]
<input type="hidden" id="submit" name="submit" value="1">


and then it would pass the submit variable through the form that your script is looking for.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

By the way I think I just figured out why your original script was not working. It was driving me crazy, the problem ended up being your HTML, not the PHP script. In your HTML you had on your original script for the form element:

HTML Code: [ Select ]
<form id="contacts-form" action="contact.php" enctype="multipart/form-data">


You were missing the method which clarifies you are doing post data. So for anybody who is getting blank $_POST variables to fix this you should verify you have your method declared like so:

HTML Code: [ Select ]
<form id="contacts-form" action="contact.php" enctype="multipart/form-data" method="post">


By default it would be using the GET method which means the variables in PHP would be accessed like so:

$_GET['variable']

instead of:

$_POST['variable']

Once you declare the method="post" then you could access via the $_POST variable in PHP.

Hopefully that helps for anybody who has this problem down the road with blank $_POST variables :)
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

nope that doesn't work in fact now the button doesn't work at all.

any more ideas?
  • garrett2828
  • Newbie
  • Newbie
  • garrett2828
  • Posts: 6

Post 3+ Months Ago

Hey James,
Could you send me your html code that you used that actually made it redirect back to your site like it was supposed to do, I did like Brian said but same results. I'm just wondering what you did to edit it and make the redirection work without trying to route to the contact.php file thanks again
Garrett
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Hi James - Took a look at your HTML, on your current script you are using you have JavaScript trying to search by ID and you have no ID specified on the form:

HTML Code: [ Select ]
<form method="POST" name="contact_form" action="contact.php">


Change that to:

HTML Code: [ Select ]
<form method="POST" id="contact_form" name="contact_form" action="contact.php">


That should get rid of that JavaScript error I am receiving. See if that resolves anything, there may be further problems still after that.
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

Garrett,

in the php file that I called contact.php look for header('Location:'); you will see a link to something like thank-you.html or something like that. change that to where you want it to be redirected to once the form has been sent.

hope that helps
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

The other problem you have James is this line:

HTML Code: [ Select ]
<script type="text/javascript" src="gen_validatorv31.js"></script>


gen_validatorv31.js does not exist on your site. It needs to be loaded from your js directory:

HTML Code: [ Select ]
<script type="text/javascript" src="js/gen_validatorv31.js"></script>
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

lol Brian,

take a look at the following HTML code and tell me where I am going wrong. I have followed your instructions and now the darn button doesn do a darn thing...not a single thing.

Code: [ Select ]
<h2>Contact Form</h2>
                            <form method="POST" id="contact_form" 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='phone'>Phone: </label><br>
                            <input type="text" name="phone">
                            </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="hidden" id="submit" name="submit" value="1">
                            <div class="alignright"><div class="alignright"><a href="contacts.html" class="link4" onClick="document.getElementById('contact_form').reset()"><span><span>Clear</span></span></a><a href="javascript: submitform()" class="link2" onClick="document.getElementById('contact_form').submit()"><span><span>Send</span></span></a></div>
                            </form>
                            <script type="text/javascript">
                            function submitform()
                            {
                             document.forms["contact_form"].submit();
                            }
                            </script>
                            <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" id="contact_form" name="contact_form" action="contact.php">
  3.                             <p>
  4.                             <label for='name'>Name: </label><br>
  5.                             <input type="text" name="name">
  6.                             </p>
  7.                             <p>
  8.                             <label for='email'>Email: </label><br>
  9.                             <input type="text" name="email">
  10.                             </p>
  11.                             <p>
  12.                             <label for='phone'>Phone: </label><br>
  13.                             <input type="text" name="phone">
  14.                             </p>
  15.                             <p>
  16.                             <label for='message'>Message:</label> <br>
  17.                             <textarea name="message"></textarea>
  18.                             </p>
  19.                             <p>
  20.                             <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
  21.                             <label for='message'>Enter the code above here :</label><br>
  22.                             <input id="6_letters_code" name="6_letters_code" type="text"><br>
  23.                             <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
  24.                             </p>
  25.                             <input type="hidden" id="submit" name="submit" value="1">
  26.                             <div class="alignright"><div class="alignright"><a href="contacts.html" class="link4" onClick="document.getElementById('contact_form').reset()"><span><span>Clear</span></span></a><a href="javascript: submitform()" class="link2" onClick="document.getElementById('contact_form').submit()"><span><span>Send</span></span></a></div>
  27.                             </form>
  28.                             <script type="text/javascript">
  29.                             function submitform()
  30.                             {
  31.                              document.forms["contact_form"].submit();
  32.                             }
  33.                             </script>
  34.                             <script language="JavaScript">
  35.                             // Code for validating the form
  36.                             var frmvalidator = new Validator("contact_form");
  37.                             //remove the following two lines if you like error message box popups
  38.                             frmvalidator.EnableOnPageErrorDisplaySingleBox();
  39.                             frmvalidator.EnableMsgsTogether();
  40.                             
  41.                             frmvalidator.addValidation("name","req","Please provide your name");
  42.                             frmvalidator.addValidation("email","req","Please provide your email");
  43.                             frmvalidator.addValidation("email","email","Please enter a valid email address");
  44.                             </script>
  45.                             <script language='JavaScript' type='text/javascript'>
  46.                             function refreshCaptcha()
  47.                             {
  48.                                 var img = document.images['captchaimg'];
  49.                                 img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
  50.                             }
  51.                             </script>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Your JavaScript file is not loading which is part of that script, it is resulting in a 404 error. Please see my last post :)

Without that loading the Javascript function on the submit button is returning this error:

Quote:
Error: document.getElementById("contact_form").submit is not a function
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

ok JS line fixed and the file is loaded into the JS directory with the rest of the js files....wait for it............it still doesnt work....lmao

The button doesnt do anything at all. Almost like JS isnt capable of submitting the form.

Cant believe I have this whole thing working, But ONLY if I use the crappy
Code: [ Select ]
<input type="submit" value="Submit" name='submit'>
code.

the site has 2 very nice combo buttons within the site code, but getting these to work is proving harder than reversing time.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Yeah its because multiple problems are going on at once here. Just gotta fix each one. Will look it over shortly.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Okay I have a new resolution for you to try. Go ahead and change this:

HTML Code: [ Select ]
<input type="hidden" id="submit" name="submit" value="1">


to:

HTML Code: [ Select ]
<input type="hidden" id="form_submit" name="form_submit" value="1">


Then in your PHP Code change this line:

PHP Code: [ Select ]
if(isset($_POST['submit']))


to:

PHP Code: [ Select ]
if(isset($_POST['form_submit']))


and see what happens :)
  • garrett2828
  • Newbie
  • Newbie
  • garrett2828
  • Posts: 6

Post 3+ Months Ago

Perfect! thanks so much!
  • jharvey1029
  • Novice
  • Novice
  • jharvey1029
  • Posts: 31
  • Loc: New Castle, PA

Post 3+ Months Ago

Brian,

you are a champion!!!!! It now works. I cant thank you enough. You have made my day, trust me been working on using this site for sometime now and finally its almost complete.

A great many thanks and if there is anything I can do for you please let me know.


James
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

No problem, glad I could help :)

Post Information

  • Total Posts in this topic: 51 posts
  • Users browsing this forum: No registered users and 18 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
 
 

© 1998-2016. Ozzu® is a registered trademark of Unmelted, LLC.