Could someone please tell me why this mailer class is so slow and what code I can do to speed it up? It takes 3 days to receive!:mad: !! And it's not the server because I have a separate contact form that emails immediately.
This slow version is integrated into my login system and it emails the admins automatically to notify them that someone registered on the site.
Here are the abbreviated versions of the code:
<?php
class Mailer
{
/** Send welcome message to the newly registered user,...*/
function sendWelcome($user, $email, $pass){
$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
$subject = "Welcome!";
$body = $user.",\n\n" ."Welcome! You've just registered at blah blah blah";
return mail($email,$subject,$body,$from);
}
/** Send message to Admin that a new registration occurred */
function sendRegNotice($user, $subemail){
$email = "admin_email@example.com";
$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
$subject = "New Registration!";
$body = "Web Administrator,\n\n"
."Someone has just registered at the site ..blah blah"
return mail($email,$subject,$body,$from);
}
};
/ Initialize mailer object /
$mailer = new Mailer;
?>
This is where I call the mailer object:
<?php
/**Session stuff goes here.....*/
if($database->addNewUser($subuser, md5($subpass), $subemail)){
if(EMAIL_WELCOME){ //THIS IS PRETTY SLOW...
$mailer->sendWelcome($subuser,$subemail,$subpass);
}
if(SEND_REG_NOTICE){ // NOW THIS IS REALLY SLOW!!!!
$mailer->sendRegNotice($subuser,$subemail);
}
return 0; //New user added succesfully
}else{
return 2; //Registration attempt failed
}
}
?>
I know this isn't a server problem
because my contact form responds really quickly with this code:
<?php
$to = "admin@example.com";
$subject = $POST['subject'];
$body = $POST['body'];
$headers = "From: " . $_POST['emailAddress'] . "\n";
mail($to,$subject,$body,$headers);
echo "Message Sent<br />You should be receiving a reply shortly.";
?>
Can anyone help me? Thank you! - Whistlepig