dsab Posted March 13, 2009 Share Posted March 13, 2009 I am trying to figure out why this will not send an email. Please help Classes file: <?php class Text_email{ public $to = ""; public $subject = ""; public $body = ""; public $header = ""; function __construct ($to, $subject, $body, $header){ $this -> to = $to; $this -> subject = $subject; $this -> body = $body; $this -> header = $header; } function sendEmail() { mail($this->to, $this->subject, $this->body, $this->header); } } ?> Index file: <?php include("./textemail.classes.php"); /* require_once("./htmlemail.classes.php"); require_once("./attachment.class.php"); require_once("./inc/connect_db.php"); */ $text_email = new Text_email($to, $subject, $body, $header); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Email</title> </head> <body> <form id="form1" name="form1" method="post" action="./index.php"> <label> Type of Email: <select name="type_select"> <option value="text">Text Email</option> <option value="html">HTML Email</option> </select> </label> <br /> <br /> <table width="700" border="0" cellspacing="0" cellpadding="3"> <tr> <td><label>To</td> <td><input type="text" name="to" id="textfield" /></label></td> </tr> <tr> <td><label>Subject</td> <td><input type="text" name="subject" id="textfield" /></label></td> </tr> <tr> <td><label>Header</td> <td><input type="text" name="header" id="textfield" /></label></td> </tr> <tr> <td><label>Attachment</td> <td><input type="text" name="attachment" id="textfield" /></label><input name="attach" type="submit" value="Browse" /></td> </tr> <tr> <td><label>Body</td> <td><textarea name="body" cols="45" rows="5"></textarea></label></td> </tr> <tr> <td><input name="send" type="submit" value="Send" /></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/149308-sending-email-using-classes/ Share on other sites More sharing options...
premiso Posted March 13, 2009 Share Posted March 13, 2009 You are never calling the send email method: $text_email = new Text_email($to, $subject, $body, $header); $text_email->sendEmail(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/149308-sending-email-using-classes/#findComment-784078 Share on other sites More sharing options...
Daniel0 Posted March 13, 2009 Share Posted March 13, 2009 I don't mean to break it for you, but your class is entirely redundant. It would be easier and more efficient to just call the mail function directly unless you are going to give your class more advanced functionality. Quote Link to comment https://forums.phpfreaks.com/topic/149308-sending-email-using-classes/#findComment-784080 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.