troubleshooting Question

PHP Mail says it was sent but never actually sends

Avatar of Michelle Jackson
Michelle Jackson asked on
PHP
4 Comments1 Solution26 ViewsLast Modified:
I am trying to build a PHP app to send query results to multiple users. When I run the program it states that the message was sent but it is not actually sent, I never receive it. I must be missing something here. Could someone please take a look and point me in the right direction?  I am using AMPPS to test this. Thanks.
<?php
//include("DBConstants.php");
$con = mysqli_connect ('xxx.xxx.xxx.xxx','loginxxx','passwordxxx');
if (!$con)
  {
  die('Could not connect:' . mysqli_error());
  }
  mysqli_select_db($con,"xxx");
  $result = mysqli_query($con,"SELECT * FROM logins WHERE logintime >=(CURRENT_DATE - INTERVAL 7 DAY)");
  $from = "xxx@xx.com";
  $host = "smtp.office365.com";
  $username = "xxxx";
  $password = "xxx";
  $port = "587";
  $to = "myemail@myemail.com";
  $subject = "Logins";
  $body = "<table border='1'>";
  $body .= "<tr>";
  $body .= "<th>LOGIN:</th>";
  $body .= "<th>TIME:</th>";
  
  $body .= "</tr>";
 while($row = mysqli_fetch_array($result)){
  $body .="<tr>";
  $body .="<td>" . $row['userid'] . "</td>";
  $body .="<td>" . $row['logintime'] . "</td>";
  
  $body .="</tr>";
  }
  $body .="</table>";
  mysqli_close($con);
  ;
  
  $headers = "Return-Path: $from\n";
  $headers .= "X-Sender: $from\n";
  $headers .= "From: $from\n";
  $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


  mail($to,$subject,$body,$headers);
  echo "Mail sent to myemail@myemail.com ";
?>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros