1

My script.php

<?php
ini_set('display_errors', 1); 
error_reporting(E_ALL);

$to      = 'myemail@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: anotheremail@domain.com' . "\r\n" .
    'Reply-To: anotheremail@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$res = mail($to, $subject, $message, $headers);
var_dump($res);
?>

php.ini essentials

sendmail_path = /usr/sbin/sendmail -t -i
mail.log = /home/myuser/phpmail.log
  • When I run script.php it takes about 30 seconds before it displays bool(true).
  • /home/myuser/phpmail.log contains entry with all headers
  • /usr/sbin/sendmail is the correct path to sendmail
  • The email does not get through. Tested several different addresses e.g. mailinator

How do I get it to work? What can i do to debug?

daker
  • 3,430
  • 3
  • 41
  • 55
  • Is your server a trusted sender for `domain.com`? – Ja͢ck Jul 30 '13 at 03:53
  • first thing i would check are the mail server logs –  Jul 30 '13 at 03:55
  • Have you checked the sendmail log? – Barmar Jul 30 '13 at 03:57
  • @Jack depends on what you mean with a trusted sender? Barmar: yes, nothing weird there i'm afraid. If I'm looking in the right place? /var/log/mail.log – daker Jul 30 '13 at 04:04
  • [This answer](http://stackoverflow.com/a/9575534/2194007) to a related question might be of interest. Hope it helps. – rath Jul 30 '13 at 08:22
  • Do you use sendmail? (or exim/postfix providing sendmail look alike) **YES** => Which sendmail version do you use? Do you have `sendmail.cf` and `submit.cf` in `/etc/mail/` ? – AnFi Jul 30 '13 at 20:13
  • @AndrzejA.Filip yes, Version 8.14.4. I have sencmail.cf and submit.cf in /etc/mail. – daker Jul 31 '13 at 01:06

2 Answers2

1

0) Check sendmail log files

1) Send a test message as the same system user

#!/bin/sh
/usr/sbin/sendmail -v -t -i <<END
To: myemail@gmail.com
Subject: the subject
From: anotheremail@domain.com
Reply-To: anotheremail@domain.com

hello
END
echo SENDMAIL EXIT CODE: $?
AnFi
  • 10,493
  • 3
  • 23
  • 47
  • No errors in senmail logs. That script worked fine, no errors and the email got sent. Why? – daker Aug 05 '13 at 12:52
0

This finally worked

Opened port 25 for localhost in iptables and removing the "i" from sendmail_path in php.ini

sendmail_path = /usr/sbin/sendmail -t
daker
  • 3,430
  • 3
  • 41
  • 55