help with contact form php?

Gary

New member
hey,

pulling my hair out over this. can anybody see where I am going wrong with this simple php contact form? every time the email comes through, all of the fields are there but the entries are blank and so is the senders address? here is the coding .. (wont show results page html as very long)

cheers,
gary



<?php

/* Subject and Email Variables */

$emailSubject = 'Box Of Frogs Contact Form';
$webMaster = '[email protected]';

/* Gathering Data Variables */

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$phoneField = $_POST['phone'];
$interestField = $_POST['interest'];
$contactField = $_POST['contact'];
$commentsField = $_POST['comments'];
$offersField = $_POST['offers'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Phone: $phone <br>
Interest: $interest <br>
Contact: $contact <br>
Comments: $comments <br>
Offers: $offers <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */
 
here use this as a guide

<?

/***********************
CLASS :: MYMail
************************/
class MyMail{
var $To;
var $ToSender;//If you want the email to go to the sender
var $Subject;
var $Msg;
var $Headers;
var $From;
var $ReplyTo;
/*
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
***&&&&&*******
For HTML Mail
'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
*/
function MyMail($To, $Subject, $Msg, $From, $ReplyTo){
$this->To=(empty($To)) ? "0" : $To;
$this->Subject=(empty($Subject)) ? "0" : $Subject;
$this->Msg=(empty($Msg)) ? "0" : $Msg;
$this->From=(empty($From)) ? "0" : $From;
$this->ReplyTo=(empty($ReplyTo)) ? "0" : $ReplyTo;
$this->Headers="MIME-Version: 1.0" . "\r\n" . "Content-type: text/html; charset=iso-8859-1" . "\r\n" . "From:" . $this->From . "\r\n" . "Reply-To:" . $this->ReplyTo . "\r\n" . "X-Mailer: PHP/" . phpversion();

//Use this array if you want to send to only one person
$SetMail=array(
'To'=> $this->To,
'Subject'=> $this->Subject,
'Msg'=> $this->Msg,
'Headers'=> $this->Headers,
'From'=> $this->From,
'ReplyTo'=> $this->ReplyTo
);
//Use this array if you want it to go to multiple people (the sender/CC:/Bcc:)
/*
$SetMail=array(
'To'=> $this->To . "," . $ToSender,
'Subject'=> $this->Subject,
'Msg'=> $this->Msg,
'Headers'=> $this->Headers,
'From'=> $this->From,
'ReplyTo'=> $this->ReplyTo
);
*/
if(in_array("0",$SetMail)){
echo "<div align=\"left\"><font color=\"#640000\">Something wrong with the mail! Please make sure all fields are filled in!</font></div>";
return;
}
else{
if(!mail($SetMail['To'], $SetMail['Subject'], $SetMail['Msg'], $SetMail['Headers'])){
echo "<script type=\"text/javascript\">window.location=\"error.php?app=Error&action=Echo&ErrorType=$this->Errors&Remarks=There is a problem with the Mail!\"</script>";
}
}
}
}
?>

and call the class like this



Code:
$MyMail=new MyMail($To="Email address", $Subject="Subject", $Msg=Message or body, $From="From email address", $ReplyTo="reply to email address.or use from email address");

and if you want a complete system you can use this too
http://bb.dzsoundnirvana.com/viewtopic.php?f=41&t=64

it does all the work for you
 
Change the following code segment:

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$phoneField = $_POST['phone'];
$interestField = $_POST['interest'];
$contactField = $_POST['contact'];
$commentsField = $_POST['comments'];
$offersField = $_POST['offers'];

To:

$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$interest = $_POST['interest'];
$contact = $_POST['contact'];
$comments = $_POST['comments'];
$offers = $_POST['offers'];
 
Back
Top