Jump to content

OOP email system


141n

Recommended Posts

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  ??? ???

Link to comment
https://forums.phpfreaks.com/topic/65084-oop-email-system/
Share on other sites

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("[email protected]", "[email protected]", "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("[email protected]", "[email protected]", "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.

Link to comment
https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324828
Share on other sites

:D

 

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 :D

Link to comment
https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324866
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-324886
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/65084-oop-email-system/#findComment-326451
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.