Reputation: 5099
Im trying to setup a basic PHP contact form and despite my best efforts I can't seem to make it work:
on contact.php my code looks like this:
include_once('form_record.php');
$obj = new formRECORD();
if ( $_POST )
$obj->send_mail($_POST);
echo $obj->display_form();
And then form_record.php looks like this:
class formRECORD {
public function display_form() {
$entry_display .= <<<ENTRY_DISPLAY
<form >
<label>Name</label><br/>
<input id="form_name"><br/>
<label>Email</label><br/>
<input id="form_email"><br/>
<label>Phone:</label><br/>
<input id="form_phone"><br/>
<label>Name</label><br/>
<textarea id="body"></textarea><br/>
<input type="submit" value="Send" />
</form>
ENTRY_DISPLAY;
return $entry_display;
}
public function send_mail($p) {
$to = "[email protected]";
$subject = "Contact Us";
$email = $_POST['form_email'] ;
$message = $_POST['body'] ;
$headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ;
if($sent) {return "Your mail was sent successfully"; } else {return "We encountered an error sending your mail"; }
}
}
The contact form shows up OK and there aren't any php errors when the user hits submit. However the email never appears in my inbox. Any ideas?
Upvotes: 0
Views: 263
Reputation: 117364
You have to set the name-attributes of the form-fields, otherwise the fields cannot be submitted. The IDs have no meaning for PHP.
Upvotes: 2