...

View Full Version : PHP Contact form



nell
01-08-2012, 01:10 PM
Hello,

I have the below contact.php file, and it is not sending emails to myself (nell@example.com). I was wondering if someone could help...? Much appreciated.

Nell


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

_Aerospace_Eng_
01-08-2012, 03:52 PM
Do you get the "message sent" print our or the "ERROR" print out? Also remove the @ from @mail. It is suppressing any errors that mail is giving back. Also check your spam box.

nell
01-08-2012, 06:07 PM
Thanks for the reply. I am getting the 'message sent' - no errors, though it's just not coming to my email inbox...

Have also removed the '@'.... and checked spam.

This is my form:

<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="email">Phone </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">
<div class="clr">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
</div>
</li>
</ol>
</form>

Is this correct?

thanks.

BluePanther
01-09-2012, 02:12 PM
Thanks for the reply. I am getting the 'message sent' - no errors, though it's just not coming to my email inbox...

Have also removed the '@'.... and checked spam.

This is my form:

<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="email">Phone </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">
<div class="clr">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
</div>
</li>
</ol>
</form>

Is this correct?

thanks.

Shouldn't that bolded input be name="phone"? Also, you've not defined types for your input fields in the form. Go back and put type="text" in all of them. I don't know how this would effect POST info (might not).

Regardless, is this correct? or did you censor your email for the post:


$your_email = "nell@example.com";

Ask your hosting provider if there's a mail server error log you can view - that will tell you specifically what's wrong. I'm not entirely sure if you can have the ':' in the subject line without escaping it, but I could be wrong on that. Check your error log for more information. If you're getting the message sent echo, PHP is returning true for the mail function which means everything's alright PHP wise. This is misleading though, as PHP only knows if it's sent the information to the mail server - it doesn't know if the mail server has actually been able to send the mail.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum