0

I'm trying to send emails in a loop and it is working fine but it prints the result to page in one go rather one by one.

What I want is, it should print a response for every email sent. This is what I have so far:

 //foreach loop
 $Response = $ObjMail->send();
 if ($Response) {
 echo "Email Sent Successfully to $val[name] </br>";
  } else {
      echo "There was an error sending Email to $val[email]";
   }
Magisch
  • 7,312
  • 9
  • 36
  • 52
Mohsin
  • 73
  • 11

1 Answers1

0

Depending on your $ObjMail, a "successfully send mail" generally will equate to

  • the sending mail server (i.e. smtp server) accepted the email or
  • the mail() function got called (actually read the doc, especially the return value part).

Email functions rarely return a very useful value, as long as the email being sent is at least somewhat plausible. It will even return true, if the email address doesn't exist, the email gets bounced, your smtp server is blacklisted, ...

The probable answer to your question: Your output is almost instantaneous by default, unless your local sendmail (the default on most hosts) call takes longer than a few microseconds, which it usually doesn't. Additionally, it doesn't say anything about the mails actually being sent. (And I assume, that you thought that was actually the case, it's not.)

My advice is, drop the stylish output and just send the mails. You can't be certain if they actually reached their target. If the $ObjMail actually returns an error, that would probably be wise to log somewhere, so that you don't repeatedly send to the same false address.

Jakumi
  • 8,043
  • 2
  • 15
  • 32