Solved

My works exchange server is not recieving mails from the php mail() function

Posted on 2008-06-26
5
222 Views
Last Modified: 2013-12-12
I have developed a script - see attached - to monitor domains at the company i work for.

The problem is that the mail isn't hitting our exchange server. When its sent to my gmail account it works fine but it gets sent straight to the spam box.

I've been looking into a PHP mail class to get this working correctly but Im having problems getting that working - Is there something i am missing that is preventing this to recieve at our exchange

The below code runs a query and sends the results to my email using the mailing function in php
<?

mysql_connect("localhost","user","password"); 

mysql_select_db("dbname") or die( "Unable to select database"); 

 

  

$query=mysql_query("SELECT * FROM `domains` WHERE `exp_date` >= '0000-00-01' ORDER BY exp_date ASC LIMIT 25");
 

if(mysql_num_rows($query)){ 
 

      $to  = "my@email.com"; 

  

      $subject = "Expiry Notice";

   

      $from = "reminder@mydomain.co.uk";

      

      $msg = "<font face='MS Sans Serif'>

Hello,</font><BR><BR>";

  

      $msg .= "<font face='MS Sans Serif'>The next 25 domains to expire are the following:</font><BR><BR>";

      

while($row=mysql_fetch_array($query))

{    

 

  

   $domain_name=$row["domain_name"];

   $company_name=$row["company_name"];

   $simply_account=$row["simply_account"];

   $notes=$row["notes"];

   $id=$row["id"];

   $exp_date=$row["exp_date"];
 
 

      

if($query == TRUE)

    {
 
 

      $msg .= "<font face='MS Sans Serif'><b>$company_name</b>: $domain_name - $exp_date </font><BR>";  
 

}
 

}	

      

      $msg .= "<BR>";
 

      $msg .= "<font face='MS Sans Serif'>Domains Admin</font><BR><BR>";

 

       

  

      $headers = "MIME-Version: 1.0" . "\r\n";

  

      $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

  

      $headers .= "From: reminder@mydomain.co.uk\r\nReply-To:reminder@mydomain.co.uk" . "\r\n";

 

       

 

      $mailsend = mail("$to","$subject","$msg","$headers");

  

      echo $mailsend ? "Email was sent :-)." : " Email sending failed :-(.";

}

?>

Open in new window

0
Comment
Question by:oku86
  • 3
  • 2
5 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 21874528
It is likely that your work account's spam filter is stopping the email. It is therefore essential to construct the email in such a way that it does not trigger the spam filter.

I would start by stripping all HTML tags and just send the email through as a simple text email. Remove all the MIME stuff in $headers. It should be easy enough to alter the script you have already and just try it out and see what happens.

Having any HTML in an email ups the spam score.

Try the code below and see if it makes any difference
UNTESTED CODE!!!
 

<?

mysql_connect("localhost","user","password"); 

mysql_select_db("dbname") or die( "Unable to select database"); 

 

  

$query=mysql_query("SELECT * FROM `domains` WHERE `exp_date` >= '0000-00-01' ORDER BY exp_date ASC LIMIT 25");

 

if(mysql_num_rows($query)){ 

 

      $to  = "my@email.com"; 

  

      $subject = "Expiry Notice";

   

      $from = "reminder@mydomain.co.uk";

      
 

      $msg = "The next 25 domains to expire are the following:\r\n\r\n";

      

      while($row=mysql_fetch_array($query))

      {    

          $domain_name=$row["domain_name"];

          $company_name=$row["company_name"];

          $simply_account=$row["simply_account"];

          $notes=$row["notes"];

          $id=$row["id"];

          $exp_date=$row["exp_date"];

               

          if($query == TRUE)

               $msg .= "$company_name: $domain_name - $exp_date\r\n";

     

      }       

      

      $msg .= '\r\n';

      $msg .= "Domains Admin\r\n\r\n";
 

      $headers = "From: reminder@mydomain.co.uk\r\nReply-To:reminder@mydomain.co.uk" . "\r\n";

      

      $mailsend = mail("$to","$subject","$msg","$headers");

  

      echo $mailsend ? "Email was sent :-)." : " Email sending failed :-(.";

}

?>

Open in new window

0
 
LVL 1

Author Comment

by:oku86
ID: 21875136
Still not reaching the exchange - i've been working along side the techie who runs our exchange server - hes allowed our email address to the whitelist in messagelabs and made several changes but nothing is coming though -

Just don't understand why its not working - we have just changed webhost to get the cron feature but is kind of pointless if the automated each cant reach us

This script worked fine on our last webhost
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 21875342
Have you access to the webserver's mail logs? Can you find the mail transaction and verify that the mail was handed off to the Exchange server?
0
 
LVL 1

Author Comment

by:oku86
ID: 21882014
From the webserver on my hosting? no i dont have but ill contact the host techie support to see whats happening

Ta

Dan
0
 
LVL 1

Accepted Solution

by:
oku86 earned 0 total points
ID: 21917095
Ive managed to sort it at.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change password links 7 72
php string masking 4 27
highcharts wont fix inside a bootstrap modal window 6 27
Split long text string into shorter chunks 7 19
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now