iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-27-2009, 02:29 AM
robert.cfi's Avatar
WebProWorld Member
 
Join Date: Dec 2008
Posts: 31
robert.cfi RepRank 1
Default PHP contact form help

I did not write this code and i cannot get it to work... I am using it legally with permission.

I am trying to submit a contact form. I normally have not used required fields thats why i had this done for me. Although now I do not know how to debug it because im not use to some of these fields. Everytime I send I get an "ERROR" which is coded to do so when it does not send properly. Ill post code of php and form.. any help will be greatly appreciated!!

contact.php
<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "sales@example.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}

if(@mail($your_email,$email_subject,$email_content )) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>


form code
<form action="assets/contact.php" method="post" id="contactform">
<ol>
<li>
<label for="name">your name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">*</span></label>

<input id="email" name="email" class="text" />
</li>
<li>
<label for="company">Company Name</label>
<input id="company" name="company" class="text" />
</li>
<li>
<label for="subject">Subject</label>

<input id="subject" name="subject" class="text" />
</li>
<li>
<label for="message">message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons">

<input type="image" name="imageField" id="imageField" src="assets/images/button_send_message.jpg" />

</li>
</ol>
</form>

Last edited by weegillis; 08-30-2009 at 04:20 AM. Reason: for public use
Reply With Quote
  #2 (permalink)  
Old 08-27-2009, 02:32 AM
robert.cfi's Avatar
WebProWorld Member
 
Join Date: Dec 2008
Posts: 31
robert.cfi RepRank 1
Default Re: PHP contact form help

i forgot the js code


<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
company: $('#company').val(),
subject: $('#subject').val(),
message: $('#message').val()
},
function(data){
$('#contactform #submit').attr('disabled','');
$('.response').remove();
$('#contactform').before('<p class="response">'+data+'</p>');
$('.response').slideDown();
if(data=='Message sent!') $('#contactform').slideUp();
}
);
return false;
});
});
// ]]>
</script>
Reply With Quote
  #3 (permalink)  
Old 08-27-2009, 05:07 PM
allaffiliatepro's Avatar
WebProWorld Member
 
Join Date: Oct 2004
Location: International
Posts: 83
allaffiliatepro RepRank 0
Default Re: PHP contact form help

Hi,
Your best bet is to delete the PHP script and find one that is written in Perl.


Lyle
__________________
Lyle Hopkins
Internet Marketing Tutorials, guides and advice
Affiliate software Advanced Affiliate Solutions
Reply With Quote
  #4 (permalink)  
Old 08-27-2009, 05:17 PM
WebProWorld New Member
 
Join Date: Dec 2005
Posts: 4
colden RepRank 0
Default Re: PHP contact form help

Quote:
Originally Posted by allaffiliatepro View Post
Hi,
Your best bet is to delete the PHP script and find one that is written in Perl.


Lyle
Your answer begs the question. Why not suggest any good site that has a collection of PHP and Perl scripts? Hotscripts is one I have used successfully. In short, his problem can be solved by using another PHP script (Perl is not necessary). Furthermore, I'd highly suggest he use a mail form that uses Captcha to foil spammers.
Reply With Quote
  #5 (permalink)  
Old 08-27-2009, 05:21 PM
WebProWorld Member
 
Join Date: Sep 2005
Location: Venice, CA
Posts: 83
visio RepRank 0
Default Re: PHP contact form help

the contact.php is in different folder assets ? is that necessary?

click on the link below, it is a simple functional contact form, you just have to edit the email you want to connect to and the thank you page:

http://ffmpeg-hosting.net/contact-form.zip

if you need more fields you just have to edit the form not the contact.php

Last edited by visio; 08-27-2009 at 05:24 PM.
Reply With Quote
  #6 (permalink)  
Old 08-27-2009, 05:23 PM
WebProWorld New Member
 
Join Date: Jan 2008
Posts: 5
enicola RepRank 0
Wink Re: PHP contact form help

i would suggest getting rid of that php too, so many spammers hack php form codes. Why not try using a service like hform.com, you can have them process the form data securely thru an encryption to there servers, store in database and email you results, have image captcha, have required fields, and an auto-responder. It's a good option for a non-programmer and the cost is so little ($2.50 a month I think). Your host service would likely be pleased that the processes are not vulnerable on your host space too. They've been around for years now and I've seen plenty of small and large scale busineses use the services, have peace of mind that your website is protected from form spammers and your email is also protected from general spambots.

If you're a programmer, you could use perl, or at least have your email kept in an ini file for better security and use code from tectite.com perhaps (they have a good one).

Hope this information helps, good luck!

Last edited by enicola; 08-27-2009 at 05:28 PM. Reason: typo
Reply With Quote
  #7 (permalink)  
Old 08-27-2009, 05:26 PM
WebProWorld Member
 
Join Date: Oct 2005
Posts: 36
wdillsmith RepRank 0
Default Re: PHP contact form help

The codes looks okay on the surface. Instead of having it just say "ERROR", try printing out some debug info to see what it is trying to do. For example:

replace:

echo 'ERROR!';

with:

echo "Unable to send to |$your_email| with subject of |$email_subject| and message of |$email_content|\n";

You might also make sure you have permission to send email at all, by hard-coding a mail call for each submission. So just throw this at the bottom of the script:

mail ("sales@distinctdesignus.com", "script completed", "Look at me, I'm the message body");
__________________
Looking for a unique gift? Send one of our gourmet cookie bouquets today.
Food lovers - visit the Gourmet Gift of the Day Blog for delicious ideas.
Reply With Quote
  #8 (permalink)  
Old 08-27-2009, 05:26 PM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Pullman, WA (from CA)
Posts: 138
a53mp RepRank 2
Default Re: PHP contact form help

Php for contact forms are fine but thatscript is kind of crappy. Look at phpmailer google it I'm on my iPhone right now but that is a lot better to use than just regular mail()
Reply With Quote
  #9 (permalink)  
Old 08-27-2009, 05:30 PM
Moderator
WebProWorld Moderator
 
Join Date: Oct 2003
Location: Alberta, Canada
Posts: 878
weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6
Default Re: PHP contact form help

The OP's problem could be solved, also, by looking for mistakes or clues in the posted code, and once that's ruled out, then suggest other code. Did they not already go to the trouble of finding and installing this code? Let's be helpful here.

First off, is your jQuery library present and loading?

Should there be a comment ( // ) in the line declaring the errors array in your PHP?

Is the PHP generating the form correctly? Check the page source in a browser and look for errors.

Trust the code you have, and make it work. No sense throwing out the baby with the bath water. A better solution, if one is to be had, will show itself when the time comes.
Reply With Quote
  #10 (permalink)  
Old 08-27-2009, 05:33 PM
WebProWorld New Member
 
Join Date: Jan 2009
Posts: 1
uzsree RepRank 0
Default Re: PHP contact form help

Make a google search for "Dagon Design PHP Form" (i am not allowed to post links, as new member)
The script is fantastic, very easy to use.
Reply With Quote
  #11 (permalink)  
Old 08-27-2009, 05:36 PM
williamc's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jul 2003
Location: GoogleVille
Posts: 1,585
williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7
Default Re: PHP contact form help

First things first. The jQuery javascipt you are using to submit the form is probably going to fail. The form action="" needs to be an entire url for the javascript to send the request properly I believe.

Secondly, this php works fine for me in testing:

Code:
<?php
  if($_POST){
    $email = $_POST['email'];
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
      $error.="Invalid email address entered";
      $errors=1;
    }
    if($errors==1){
      echo $error; 
    }
    else{
      $values = array ('name','email','message');
      $required = array('name','email','message');
      $your_email = "sales@distinctdesignus.com";
      $email_subject = "New Message: ".$_POST['subject'];
      $email_content = "new message:\n";

      foreach($values as $key => $value){
        if(in_array($value,$required)){
          if ($key != 'subject' && $key != 'company') {
            if( empty($_POST[$value]) ) { 
              echo 'PLEASE FILL IN REQUIRED FIELDS'; 
              exit; 
            }
          }
          $email_content .= $value.': '.$_POST[$value]."\n";
        }
      }
      if(@mail("$your_email", "$email_subject", "$email_content", "From: $your_email")) {
        echo 'Message sent!'; 
      } 
      else {
        echo 'ERROR!';
      }
    }
  }
?>
__________________
William Cross
Expert Search Engine Optimization
Reply With Quote
  #12 (permalink)  
Old 08-27-2009, 05:38 PM
zbatia's Avatar
WebProWorld Pro
 
Join Date: Jul 2003
Location: Baltimore, MD
Posts: 130
zbatia RepRank 1
Default Re: PHP contact form help

I agree with enikola. I have abandoned PHP long time ago. I am using the CofeeCup WebForm Builder that designs beautiful flash-based forms that is not easy to hack and it does not reveal the e-mail address. You have everything you need (redirection, CAPTCHA, instant verification, colors, pics, more!
I have seen some attempts to hack it by filling out the garbage text and see where it goes but that's all: No interest because you can see nothing inside!
__________________
The Cyber Teacher
http://www.rtek2000.com
http://www.800-webdesign.com/web-master-links.html -Free Web Master's Resources
_________________
Reply With Quote
  #13 (permalink)  
Old 08-27-2009, 05:40 PM
chrisJumbo's Avatar
WebProWorld Veteran
 
Join Date: Oct 2005
Location: California
Posts: 339
chrisJumbo RepRank 3chrisJumbo RepRank 3
Default Re: PHP contact form help

First, I compared yours to what we use.

I noticed that my @mail has four parameters. A 4th parameter is the "From" address. I define it as such:
$to = "youremail@yourdomain";
$headers = "From: $to";

So my @mail looks like :
@mail($to, $subject, $body, $headers)
Our ISP required that field.

I added some additional checking functions that I had found suggested elsewhere. Also, I found it helpful to use echo statements when I was in the process of debugging to make sure variables and such had the expected information.

Your welcome to PM me if you want me to send you the code we use.

cd :O)
__________________
CD Rates | CD Rates Blog | Banking Online
Reply With Quote
  #14 (permalink)  
Old 08-27-2009, 05:54 PM
puamana's Avatar
WebProWorld Member
 
Join Date: Sep 2006
Location: Medford, OR
Posts: 65
puamana RepRank 0
Default Re: PHP contact form help

One question... did you save the form document with a .php file extension?

I've personally moved away from contact forms because of the spambot problem,
but recently came across a php script with a simple 'captcha' that is relatively easy
to install, by changing only a few settings in the config file.

freecontactform.com - there is a free and professional version.

puamana
Reply With Quote
  #15 (permalink)  
Old 08-27-2009, 06:51 PM
WebProWorld Member
 
Join Date: Dec 2007
Posts: 63
microtekblue RepRank 0
Smile Re: PHP contact form help

You need to do a better job writing your php code.

Here is a very good tutorial to help get you started coding your own php forms.

It has good php validation, and all you gotta add in is mail() to send out the form.

PHP form tutorial
__________________
Ontario Traffic Ticket Forum
Reply With Quote
  #16 (permalink)  
Old 08-27-2009, 07:04 PM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Pullman, WA (from CA)
Posts: 138
a53mp RepRank 2
Default Re: PHP contact form help

I am on a computer now.. it looks like you are getting the ERROR when actually trying to send the mail.

if(@mail($your_email,$email_subject,$email_content )) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}

so do this.. in your page, or create a new page...

<?php
mail("youremail@email.com","test","test content");
?>

and run it.

Did you receive the email?

NO...
do you get any errors on the page or in your error_log? Does your server even have mail() enabled? try running it without the @ in front of the mail, then check for errors.

YES...
try echoing out your mail call.
change
if(@mail("$your_email", "$email_subject", "$email_content", "From: $your_email")) {
echo 'Message sent!';
}
else {
echo 'ERROR!';
}

to
echo "$your_email", "$email_subject", "$email_content", "From: $your_email"; exit;

and see what it says.
Reply With Quote
  #17 (permalink)  
Old 08-27-2009, 07:51 PM
Moderator
WebProWorld Moderator
 
Join Date: Oct 2003
Location: Alberta, Canada
Posts: 878
weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6
Default Re: PHP contact form help

Quote:
Originally Posted by williamc View Post
The form action="" needs to be an entire url for the javascript to send the request properly I believe.
or at least something relative to the site root, like "/assets/.."

The above post points to related problem, so the URL is probably the only fly in the ointment, all other things being correct.
Reply With Quote
  #18 (permalink)  
Old 08-27-2009, 08:00 PM
WebProWorld New Member
 
Join Date: Jul 2009
Location: London, KY
Posts: 9
fieldsimc RepRank 0
Default Re: PHP contact form help

One thing I seen that's missing security wise is the strip_tags function. Always use this when receiving form input. If you are relaying information from a form to a database, always use mysql_real_escape_string with the strip_tags.
Reply With Quote
  #19 (permalink)  
Old 08-28-2009, 06:28 AM
WebProWorld Member
 
Join Date: Nov 2004
Location: Rutland, GB
Posts: 40
markrchisholm RepRank 0
Default Re: PHP contact form help

Pretty much what a53mp said, but I would change:

if(@mail("$your_email", "$email_subject", "$email_content", "From: $your_email")) {
echo 'Message sent!';
}
else {
echo 'ERROR!';
}

to somthing like:

if(@mail("$your_email", "$email_subject", "$email_content", "From: $your_email")) {
echo 'Message sent!';
}
else {
echo "email: " . $your_email . "<br>subject: " . $email_subject . "<br>content: " . $email_content . "<br>from: " . $your_email;
}


This is where the error is occuring, so if you echo out the variables you will be able to see if any are wrong.
Reply With Quote
  #20 (permalink)  
Old 08-28-2009, 06:32 AM
WebProWorld Member
 
Join Date: Nov 2004
Location: Rutland, GB
Posts: 40
markrchisholm RepRank 0
Default Re: PHP contact form help

Also, I'm no php expert but can someone confirm if:

if(@mail(

is correct, should it not be:

if(mail(
Reply With Quote
  #21 (permalink)  
Old 08-28-2009, 09:00 AM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Pullman, WA (from CA)
Posts: 138
a53mp RepRank 2
Default Re: PHP contact form help

Quote:
Originally Posted by markrchisholm View Post
Also, I'm no php expert but can someone confirm if:

if(@mail(

is correct, should it not be:

if(mail(
using @ will just suppress any errors. For example, if you use unlink($file); and $file does not exist, the user will probably see a php error on the page. If you do @unlink($file); the user will not know that there was an error.

Doing if(@mail( is a bit redundant.
Reply With Quote
  #22 (permalink)  
Old 08-28-2009, 09:48 AM
WebProWorld Member
 
Join Date: Nov 2004
Location: Rutland, GB
Posts: 40
markrchisholm RepRank 0
Default Re: PHP contact form help

Learn something every day
Reply With Quote
  #23 (permalink)  
Old 08-28-2009, 11:59 AM
WebProWorld New Member
 
Join Date: Dec 2008
Posts: 5
itmdesign RepRank 1
Default Re: PHP contact form help

I haven't looked a the code in any detail but is your server set up to allow emails to be sent from 'nobody'? If not, you could try enabling that, or better still, define the 'from' field in the process page itself. No real need to move away from php, there are plenty of tutorials out there that show you how to add captcha fields without any advance knowledge in php. Just make sure you set up a lot of very different, fairly complex captcha images
Reply With Quote
  #24 (permalink)  
Old 08-30-2009, 02:22 AM
robert.cfi's Avatar
WebProWorld Member
 
Join Date: Dec 2008
Posts: 31
robert.cfi RepRank 1
Default Re: PHP contact form help

Hey guys, sorry i had the flu the last couple days and did not get a chance to see any replies.

Any simple solutions/fixes that I can get a page up an running quickly. I like how this would just say at the top of the contact form if it was sent or not instead of doing a whole new page for that. I am not an expert in contact forms and im not an expert with php but i can decode (sorta)

easy fix ideas? not worried about security right now.
Reply With Quote
  #25 (permalink)  
Old 08-30-2009, 02:54 AM
robert.cfi's Avatar
WebProWorld Member
 
Join Date: Dec 2008
Posts: 31
robert.cfi RepRank 1
Default Re: PHP contact form help

Ummm, i think i made a big mistake.

THis may or may not affect this but I am using a windows based server but running PHP..

That is a no no right?
Reply With Quote
  #26 (permalink)  
Old 08-30-2009, 09:25 AM
Uncle Dog's Avatar
WebProWorld Pro
 
Join Date: Apr 2008
Location: Scotland
Posts: 254
Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5
Default Re: PHP contact form help

No, it's a yes yes. PHP and windows will play very happily together (provided that php.ini is configured correctly).
Reply With Quote
  #27 (permalink)  
Old 08-30-2009, 09:52 AM
WebProWorld Veteran
WebProWorld MVP
 
Join Date: Oct 2006
Posts: 892
innominds RepRank 4innominds RepRank 4innominds RepRank 4innominds RepRank 4innominds RepRank 4
Default Re: PHP contact form help

If I'm not wrong, wordpress has got a contact form plugin too.
You may use it if the site is powered by wordpress.
Reply With Quote
  #28 (permalink)  
Old 08-30-2009, 01:47 PM
Doc's Avatar
Doc Doc is offline
WebProWorld Veteran
WebProWorld MVP
 
Join Date: Jun 2009
Location: Baja California
Posts: 688
Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9Doc RepRank 9
Default Re: PHP contact form help

This will probably not be a very popular answer, but it's a method I used, while I was still in the process of trying to learn php.

Email Me Form™ - HTML Forms, Web Forms, PHP Forms offers a fully customizable email me form, with "must enter" and captcha included, that is very simple to use, and requires no ads or credits back to them.
The free version, however, is actually hosted on their site, which I highly recommend against, for obvious security reasons. There is also a one-time charge of $3.95 USD, and you can then download the entire code for placement on your site, which is what I opted for.

I definitely would have preferred to write my own, but time was pressing, and I hadn't gotten to that level yet. This is serving me well in the meantime.
__________________
If I ever stop learning, let the wolves have my carcass.
http://doccampbell.wordpress.com/
http://cleanstreamwaterconditioning.com
http://carforums-online.com
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact Form without Spam mib Internet Security Discussion Forum 6 09-28-2009 05:19 PM
Simple contact form help...please!? andthen Web Programming Discussion Forum 9 08-13-2009 01:06 PM
Contact Form owt200x Internet Security Discussion Forum 0 01-15-2009 05:14 PM
Need to Build a Contact Form brianzajac Web Programming Discussion Forum 0 06-05-2006 06:20 PM
Contact Form being Hi-jacked - HELP! fisher318 Internet Security Discussion Forum 4 09-12-2005 03:14 PM


All times are GMT -4. The time now is 10:56 PM.



Search Engine Optimization by vBSEO 3.3.0