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 16th, 2011, 6:47 am

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
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 16th, 2011, 6:47 am

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

Post October 16th, 2011, 9:22 am

Hi James, please post your code here, both the HTML and PHP file so that we can take a look.
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 16th, 2011, 9:26 am

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
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 16th, 2011, 9:42 am

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?
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 16th, 2011, 10:02 am

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
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 16th, 2011, 10:04 am

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
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 16th, 2011, 11:12 am

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 !#$%&'*+-/=?^_`{|}~@.[].
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 16th, 2011, 5:08 pm

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
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 16th, 2011, 10:49 pm

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.
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, 6:38 am

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
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 17th, 2011, 8:53 am

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
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 17th, 2011, 9:22 am

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!
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:22 am

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
  • No Avatar
  • Joined: Oct 15, 2011
  • Posts: 31
  • Loc: New Castle, PA
  • Status: Offline

Post October 17th, 2011, 9:22 am

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
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 17th, 2011, 9:25 am

The PM system here should work, are you receiving some sort of error message?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 17th, 2011, 9:25 am

Post Information

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

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