0

In an attempt to send mails from a php script, I am testing the mail() function with this code:

<?php  
ini_set("display_errors", "1");
error_reporting(E_ALL);
$to = 'example@gmail.com';
$message = 'test';
$from = 'test@gmail.com';
$subject = 'Test';
$headers = "From: $from\n";
mail($to, $subject, $message, $headers) or die ("Message not sent");
?>  

This is not the only code I have tried it with, but nothing seems to be working. One of the reasons I am inquiring here is because it returns no errors whatsoever. I get no indication of any error at all, except that the mail never reaches it's destination. Things that I have done to try and fix the problem:

  1. Changed the SMTP in php.ini from localhost to gmail's smtp
  2. Checked spam filters and outboxes on both ends
  3. Tried various methods of error reporting
  4. Tried several different functions for sending mail
  5. Checked seemingly related things in phpinfo() and looked them up to no avail

I think it may be an issue with the sendmail function in my terminal, but I have no way to test or fix any issues related to the sendmail function.

I am running apache 2.0 on a PPC Mac with OS X 10.4 Tiger and PHP 5.3.12.

jstrieb
  • 599
  • 1
  • 7
  • 20
  • How many email addresses have you sent to as part of your testing? Are you verifying the mail is being sent but is being filtered by spam filters? – John Conde May 26 '12 at 16:39
  • I have tried several, like 5 or 6. If the emails are being filtered by a spam filter, I don't know where they're going because I can't find them in the spam folder. – jstrieb May 26 '12 at 16:47
  • OK, that's important for us to know so we can rule out a common cause of missing emails. – John Conde May 26 '12 at 16:51

1 Answers1

1

The SMTP settings in php.ini is for Windows only. On other systems the local MTA (Sendmail) is used, always, and the SMTP settings you provide is silently ignored. If you want to use Gmail, make sure that you configure it in your MTA.

Check the mail logs from Sendmail on the sending system. You should be able to find hints about message delivery in there.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
  • How exactly do I do that? Also, thanks for the instant response! – jstrieb May 26 '12 at 16:44
  • This is a complex topic and depends heavily on a couple of things, most importantly what MTA you use (it's often not Sendmail nowadays but some other MTA disguised behind the `sendmail` command). I cannot give such help because I can't know what settings you have, what settings you require for your specific site and most importantly it's often a complex topic, requiring an hour or two of work. You should be able to find out what you need by googling a bit but I am not able to help you that much. Also, I don't run OSX. – Emil Vikström May 26 '12 at 16:49