Jump to content

contact form - no sender


nzGoner

Recommended Posts

well... some part works! when i check my email, it says "nobody" instead of the senders email and it is not showing the right subject and the company field wont show up

 

 

here is my html code

 

thanks :(~

 

Code

 

 

<form action="contact.php" method="POST" id="contactform">

            <ol>

              <li>

                <label for="name">First 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</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="images/send.gif" class="send" />

                <div class="clr"></div>

              </li>

          </ol>

        </form>

 

 

 

here is my php

 

Code

 

 

<?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 = "gilbylu@gmail.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!';
}
}
?>

Link to comment
Share on other sites

Well, the first thing that strikes me is that there is no submit button, and you need a submit button to send a form! And on the receiver script there is no error handler for the $_POST array for if it isset() but not having the value you expect, also the ereg function has been officially superseded by preg, I forget which version of PHP, but it's something that is best fixed now.

 

And seriously, the @ prefixing the mail() is a bad Idea, it only returns a boolean so personally I would leave it so that you get AS MUCH information back from the function as possible, the mail() isn't very helpful anyway as it doesn't really give any confirmation on the successful sending of an email until it actually arrives in the inbox (I would check the junk folder too, the get in there sometimes...)

 

Lastly, you need to run the strip_tags() function over the entire $_POST array so that potentially malicious code can be stripped from the user submitted data - NEVER trust a user!

 

Hopefully some of that makes sense.

 

Rw 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.