12-02-2011, 07:27 PM
|
#7 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
Now implemented phpMailer. Still taking an eternity. Am i using this incorrectly? Its working fine but feels like it isnt running any quicker than the standard php mail() function. here my code:
I'm looping round 60 times and sending out the same email to several addresses. I had hoped that phpmailer would speed things up by opening the mail port once and not for every loop:
PHP Code:
<?php
class Message {
public function __construct() {}
/* Send Email Message(s) */
public function sendMessage($subject=null,$recipients=null,$from=null,$content=null) {
require_once('phpmailer.class.php');
if (is_array($recipients)) {
foreach ($recipients as &$email_recipient) {
If ($this->send($email_recipient,$subject,$content,$from) == False) {
return false;
}
}
unset($email_recipient); // break the reference with the last element
} else {
If ($this->send($recipients,$subject,$content,$from) == False) {
return false;
}
}
}
/* Send Email Message(s) */
private function send( $recipient, $subject, $content, $from ) {
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $content;
$mail->AddReplyTo($from,$from);
$mail->SetFrom($from, $from);
$mail->AddAddress($recipient, $recipient);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
$this->failure = True;
}
return True;
}
}
?>
|
|
|
|