airportmarc Posted May 1, 2010 Share Posted May 1, 2010 Hello all, I am looking at the best way to implement an email system. I have a class that can email the person, but I have a lot of different messages that I might have to send. I wanted to know if my line of thought was efficient. Would it be a good idea to have a class that had all the possible email messages in it, and I would send it a key word to retrieve the proper message. Then if I had to email 100-300 people, would I create the class so that each instance of the class would send 1 email to a person, then destroy the class create a new one, etc... Or would it be better to send the class the list of people the Email should be sent to, and then have the looping occur within the class? Any ideas or suggestions would be great. Thanks All Quote Link to comment https://forums.phpfreaks.com/topic/200353-an-email-system/ Share on other sites More sharing options...
ignace Posted May 1, 2010 Share Posted May 1, 2010 It would be best if your class resembles the e-mail. Then add the people you wish to e-mail to the "to:" field (comma separated) Something like: class Email { private $to, $subject, $message, $headers, $parameters; public function __construct($from, $subject, $message) { $this->subject = $subject; $this->message = $message; $this->addHeader('From', $from); $this->addHeader('Return-Path', $from); $this->addHeader('Reply-To', $from); } public function addTo($to) { $this->to[] = $to; } public function addHeader($name, $value) { $this->headers[] = "$name: $value"; } public function send() { $to = implode(',', $this->to); $headers = implode("\r\n", $this->headers); $message = wordwrap($this->message, 70); $message = str_replace("\n.", "\n..", $message); return mail($to, $this->subject, $message, $headers, $this->parameters); } } Use as: $mail = new Mail('youremail@somewhere.com', 'Hello World', 'Lorem Ipsum dolor sit amet consectuer adipiscing elit'); $to = file('emails.txt', FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES); foreach ($to as $email) $mail->addTo($email); if ($mail->send()) { //send } Quote Link to comment https://forums.phpfreaks.com/topic/200353-an-email-system/#findComment-1051456 Share on other sites More sharing options...
khr2003 Posted May 2, 2010 Share Posted May 2, 2010 or use phpmailer http://phpmailer.worxware.com/index.php?pg=examples Quote Link to comment https://forums.phpfreaks.com/topic/200353-an-email-system/#findComment-1051919 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.