开发者

Basic PHP contact form issue

开发者 https://www.devze.com 2023-03-10 06:12 出处:网络
Im trying to setup a basic PHP contact form and despite my best efforts I can\'t seem to make it work:

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 = "example@gmail.com"; 
        $subject = "Contact Us"; 
        $email = $_POST['form_email'] ; 
        $message = $_POS开发者_如何学GoT['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?


You have to set the name-attributes of the form-fields, otherwise the fields cannot be submitted. The IDs have no meaning for PHP.

0

精彩评论

暂无评论...
验证码 换一张
取 消