0

I am getting user records from the database and have to send them emails one by one. My issue is that some times the email is successfully received on some email accounts, but some times the intended recipient never receives it. The behaviour is very strange for me. My php code is below:

while($row = mysqli_fetch_array($result)){

    // current Date Time
    $now = new DateTime();
    $dateTime = $now->format('F j, Y, g:i a');

    // generate results email
    $name = $row['name'];
    $to = $row['email'];
    $subject = "subject title";
    $header = "from: myname";
    $message = "
                Date: " . $dateTime . "  

                Some text.......
                ";  

    $sentmail = mail($to,$subject,$message,$header);

    if($sentmail){
        print_r("Email successfully sent to " . $to . " <br/>");
    }
    else{
        print_r("Error in sending email to " . $to . " . Please re-try <br/>");
    } 

}

Are there any local smtp configurations that I need to adjust. Here is my sendmail_path = /usr/sbin/sendmail -t -i in php.ini

Corporal
  • 157
  • 3
  • 14

1 Answers1

-2

It would be better to send the email using phpMailer.

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
bhavesh
  • 68
  • 1
  • 1
  • 6