141n Posted August 15, 2007 Share Posted August 15, 2007 Hey guys, I'm curently developing a site that is gonna use the php mail function for different stuff, like report faults, repot abuse, general queries. What I was wondering is, would it be possible to have the one email page (say mail.php) that would use a php require() to include whatever file is needed depending on what the user selected? i.e, if the user clicks "Report A Fault" then it would got to mail.php and this page would then require('../src/report_fault.php'); likewise for the other possibilities. Problem is, I'm not too sure how to do this. I was wondering if I could set a variable like $form = '#whatever user selected' when they click the hyperlink and depending on what this variable was set to, then it would open the relevant file? I thought about if I could use $_GET[''] and set the url to something like mail.php?action=report_fault - I've seen stuff like that done before, but have no idea how to do this... can someone please help ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/ Share on other sites More sharing options...
Daniel0 Posted August 15, 2007 Share Posted August 15, 2007 You could do something like this: <?php class Mailer { function send($to, $from, $subject, $body) { $headers = "From: {$from}\r\n"; $headers .= 'X-Mailer: PHP/'.phpversion(); return mail($to, $subject, $body, $headers); } } class FaultReport extends Mailer { function __construct($error_id, $error_msg, $file, $line) { $time = date('r'); $body = <<<EOF Error [{$error_id]}: {$error_msg} in {$file} on line {$line} Time: {$time} EOF; $this->send("admin@example.com", "no-reply@example.com", "Error [{$error_id}]", $body); } } class AbuseReport extends Mailer { function __construct($reason, $reporter_uid, $offender_uid) { $body = <<<EOF User UID {$reporter_uid} reported user UID {$offender_uid} with the following reason: {$reason} EOF; $this->send("admin@example.com", "no-reply@example.com", "Abuse report", $body); } } new FaultReport(38, "Test Error", __FILE__, __LINE__); new AbuseReport("Just testing...", 5, 108); ?> Just call the class you want for the type of mail that should be sent. Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324828 Share on other sites More sharing options...
141n Posted August 15, 2007 Author Share Posted August 15, 2007 mate, I took one look at your app and thought "....wtf ???" lol - I didn't think it would be so complicated as this. I'm very n00b15H with OOP. I'm gonna start gearing my code towards it though - it seems the sensible thing to do for stuff like this Been scouring around this site and others on the net. I'm sure once I get my heard around the logic of it, it'll be easy enough, thanks - I can now pick away at your example as my first proper OOP application Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324866 Share on other sites More sharing options...
Daniel0 Posted August 15, 2007 Share Posted August 15, 2007 It isn't particularly complicated. Feel free to ask if there is anything you don't understand in the code I posted though Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324876 Share on other sites More sharing options...
141n Posted August 15, 2007 Author Share Posted August 15, 2007 Most of it I can understand, I'm just trying to break away from my bad habit of coding everything using "If()" statements Is there any particularly good literature I could read up on? I started of learning from Larry Ullman's PHP & MySQL but it wasn't too OOP geared. EDIT: Everything up to the class for ReportFault I haev a fair idea of whats going on - after that it is pretty sketchy. Bearing in mind I have only started looking at OOP the last few days Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324886 Share on other sites More sharing options...
Daniel0 Posted August 15, 2007 Share Posted August 15, 2007 I haven't read any PHP book, so I can't really recommend one. You could always try the manual: http://php.net/oop5 There are also some tutorials on the main site. Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324892 Share on other sites More sharing options...
steelmanronald06 Posted August 17, 2007 Share Posted August 17, 2007 mate, I took one look at your app and thought "....wtf ???" lol - I didn't think it would be so complicated as this. I'm very n00b15H with OOP. Hmm...I see 3 "computer lingo" terms in once sentence...this scares me. On another note, if you go to google and type: OOP mail() you will find some excellent tutorials on using OOP and mail() together, plus it breaks it down. Quote Link to comment https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-326451 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.