6

I'm trying to send mail via the PHP mail() function which as far as I have understood uses sendmail to deliver the goods. Now my problem is that mail() returns true but there is not even a trace of the mail in my mailbox (yea i checked spam too).

So i tried to send some mail manually from the terminal but the problem persists. sendmail does not give me an error, except from a unable to determine domain error which i fixed by adding the domain for my dev-machine to /etc/hosts and related it to 127.0.0.1.

andreas@Andreas-PC-Ubuntu:~$ sendmail xxxxxxx@xxxxxxx.com
Test
.
andreas@Andreas-PC-Ubuntu:~$

As well as giving no error, sendmail logs that the mail was sent successfully in /var/log/mail.log:

Apr  7 01:16:21 Andreas-PC-Ubuntu sendmail[11759]: q36NGIfD011759: from=andreas, size=5, class=0, nrcpts=1, msgid=<201204062316.q36NGIfD011759@home.hagenz.com>, relay=andreas@localhost
Apr  7 01:16:21 Andreas-PC-Ubuntu sm-mta[11760]: q36NGL1J011760: from=<andreas@home.hagenz.com>, size=299, class=0, nrcpts=1, msgid=<201204062316.q36NGIfD011759@home.hagenz.com>, proto=ESMTP, daemon=MTA-v4, relay=ip6-localhost [127.0.0.1]
Apr  7 01:16:21 Andreas-PC-Ubuntu sendmail[11759]: q36NGIfD011759: to=xxxxxxx@xxxxxxx.com, ctladdr=andreas (1000/1000), delay=00:00:03, xdelay=00:00:00, mailer=relay, pri=30005, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (q36NGL1J011760 Message accepted for delivery)

So yea, any suggestions?

Andreas Hagen
  • 2,335
  • 2
  • 19
  • 34

2 Answers2

4

Are you sure the recipient SMTP server isn't dropping (or at least greylisting) your mail? It's very common for mail servers to treat messages not coming from a recognized MX server as being spammy.

Is sendmail configured to use an SMTP relay/smarthost? If not, what happens if you configure it to use your ISP's, employer's, or other hosting provider's server?

Conrad Shultz
  • 8,748
  • 2
  • 31
  • 33
  • That is probably part of the issue yes, I'm using standard config for sendmail which was installed along from the Ubuntu repositories. How do I do this? On a sidenote, if the recipient server drops it due to bad MX setup, how is it that from my primary hosting server (I didn't set up sendmail on this so no clue how it works) I am able to supply whatever from address I'd like and everything is delivered fine? I'm sorry if some of this is kind of obvious, but this is my first time working with mail :) – Andreas Hagen Apr 06 '12 at 23:53
  • Your hosting provider probably setup mail relaying for you, akin to you entering an "outgoing mail server" when setting up a mail client on your desktop or smartphone. Do you know if Ubuntu is using exim as its sendmail implementation? – Conrad Shultz Apr 06 '12 at 23:58
  • No, I'm sorry I do not know. Is there a parameter i can supply to sendmail to make it print that information or something? – Andreas Hagen Apr 07 '12 at 00:01
  • What do you get from `dpkg -l | grep exim`? (Btw, this is rapidly evolving into a question better suited to the Linux StackExchange or ServerFault.) – Conrad Shultz Apr 07 '12 at 00:02
  • Ye I see it does. As for `dpkg -l | grep exim`, it gives me nothing. – Andreas Hagen Apr 07 '12 at 00:08
  • Well, I suggest searching google or the aforementioned sites for info in configuring mail relaying in Ubuntu. Sorry I'm not of more help, but I think this is the underlying problem. – Conrad Shultz Apr 07 '12 at 00:12
1

have you set up the configuration in your php.ini file?

When i setup php on my own server (I was running IIS on server 2003, with Exchange for emails), I had to edit the php.ini file to configure the Mail function.

Just had to uncomment andspecify my mail server for the SMTP part.

Edit

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = #mymailserver#
; http://php.net/smtp-port
smtp_port = 25

You will probably have to do the same, or similar, depending on your web server environment

Community
  • 1
  • 1
OACDesigns
  • 2,279
  • 14
  • 24
  • No, the php.ini sendmail config is just the default, but i supply the from address myself via $additional_headers and sendmail binary is located where default php.ini will try to look for it. Moreover the error I'm most interested in solving here seams to be with sendmail itself not PHP, as i described it does not send mail. – Andreas Hagen Apr 06 '12 at 23:39
  • I take it this is your server? – OACDesigns Apr 06 '12 at 23:54
  • Yes, as i said in the question it is my development machine actually. – Andreas Hagen Apr 06 '12 at 23:55
  • oh sorry, didn't see that part. i've edited my answer, however my experience was with server 2003 running exchange for emails. You may need to edit a different part of the php.ini file as you're on linux (Ubuntu i assume from your quesition) – OACDesigns Apr 06 '12 at 23:59
  • Yes, if I'm not mistaken its the config directives sendmail_path and sendmail_from i need to configure. As described in the first comment i believe that they are not the problem since mail() returns true indicating a success in the binding between PHP and sendmail. Moreover the same issue persists without the PHP layer, when I use sendmail directly from the terminal, leading me to suspect some error with sendmail. – Andreas Hagen Apr 07 '12 at 00:07
  • ah ok, got ya. Sorry I can't help you with this one. Sendmail configuration is out of my area. – OACDesigns Apr 07 '12 at 00:11