Object Oriented PHP Email Contact Form Not Sending -
i have done quite few contact forms in php no problem, i'm new oop , can't quite wrap head around how should work. i'm working tutor helping me self teach this, giving me resources learn oop, i'm stuck on this. make simple contact form send user info email specified on same form. these requirements:
the user class should:
contain relevant submitted data properties of class
have constructor method let declare class , set data in 1 statement
the email class should:
be static
have method let send email in 1 statement
have method replace formatting tags ([b] / [i] / [[name]]) proper equivalent
have proper access methods (private / public)
i'm not worried validation or syntax conversion right want work through why email isn't sending.
runner.php:
<?php class user { public $firstname; public $lastname; public $toemail; public $fromname; public $fromemail; public $subject; public $message; public function post() { if (isset($_post['submit'])) { $mail = new email($_post['firstname'], $_post['lastname'], $_post['toemail'], $_post['fromname'], $_post['fromemail'], $_post['subject'], $_post['message']); $mail->toemail = $post['$toemail']; $mail->sendmail(); } } } class email { private $fristname; private $lastname; private $toemail; private $fromname; private $fromemail; private $subject; private $message; public static function __construct($firstname, $lastname, $toemail, $fromname, $fromemail, $subject, $message) { $this->firstname = $firstname; $this->lastname = $lastname; $this->toemail = $toemail; $this->fromname = $fromname; $this->fromemail = $fromemail; $this->subject = $subject; $this->firstname = $message; } function sendmail($mail) { $contents = "to: $firstname $lastname<br />from: $fromname<br />subject: $subject<br />message: $message"; $headers = "from:" . $fromemail; $sendmail = mail($this->toemail, $this->subject, $this->message, $this->contents, $headers); } } ?>
form.html:
<html> <head> </head> <body> <form action="runner.php" method="post"> <b>to</b></br> <label>first name</label> <input type="text" name="firstname" id="firstname"></br> <label>last name</label> <input type="text" name="lastname" id="lastname"></br> <label>email</label> <input type="text" name="toemail" id="toemail"></br></br> <b>from</b></br> <label>name</label> <input type="text" name="fromname" id="fromname"></br> <label>email</label> <input type="text" name="fromemail" id="fromemail"></br></br> <b>compose email</b></br> [b]<b>bold</b>[\b] , [i]<i>italic</i>[\i] tags permitted in email body</br> <label>subject</label> <input type="text" name="subject" id="subject"></br> <label>body</label> <textarea name="message" id="message"></textarea></br></br></br> <input type="submit" value="submit"></form> </body> </html>
i don't know if i'm on right track this. help/resources appreciated.
i might wrong, think it's $contents
variable. you've set within sendmail
class, used $this->contents
. try setting private $contents;
instance variable, or use $contents
on line:
$sendmail = mail($this->toemail, $this->subject, $this->message, $this->contents, $headers);
(should be:)
$sendmail = mail($this->toemail, $this->subject, $this->message, $contents, $headers);
Comments
Post a Comment