1

I have a function for email, please find the code below:

function sendEmail($userName, $password, $sendTo, $sendToName, $subject, $body, $mailSent){

        $mail             = new PHPMailer();
        // $body             = eregi_replace("[\]",'',$body);

        $mail->IsSMTP(); // telling the class to use SMTP
        --------
        --------
        --------

        $mail->SetFrom($userName, 'Rajendra Arora');

        $mail->AddReplyTo($userName,"Rajendra Arora");

        $mail->Subject    = $subject;

        $mail->Body    = $body; // optional, comment out and test
    }

This email function has an attachment with long file size but whenever this email function is called by using sendEmail();. It is executed everytime and takes much time as it has to go through the whole execution program with primarily upload.

Is there any way to execute this sendEmail()function only for once time. So that we could call it simply once and saves time from preventing to upload?

8
  • Memoization is valid only for function that have no side effects. The function you're talking about probably sends mail, but it's unclear from description. Jun 17, 2017 at 11:41
  • What I mean to say, can we execute this whole sendEmail() function only for once time. so that whenever next time we call sendEmail() anywhere, It has not to go through the whole sendEmail() function and simply it implies with already execution with upload file changes.
    – Ramesh
    Jun 17, 2017 at 11:45
  • File upload takes time because SMTP needs to upload the file every time you send a letter. Everything else takes almost no time. Jun 17, 2017 at 11:47
  • Exactly, Thanks anyway .. @jens108 has already pointed me some suggestion. :)
    – Ramesh
    Jun 17, 2017 at 11:49
  • Beware that all recipients will know emails of each other then. Jun 17, 2017 at 11:51

1 Answer 1

0

If your emails have the same contents, you can send the same mail to multiple users: you just need to call the AddAddress method once for every recipient. Like so:

$mail->AddAddress('[email protected]', 'Person One');
$mail->AddAddress('[email protected]', 'Person Two');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.