# php postfix does not send mail [solved]

## Soynuts

I've been battling with this for a while and I can not figure out why PHP is not sending out an email when I call the mail() method.  There are no weird error messages in /var/log/messages, this is all I see:

 *Quote:*   

> Nov 28 22:12:55 MyBox postfix/qmgr[25431]: E108EE7CA7E: from=<apache@mydomain.com>, size=949, nrcpt=1 (queue active)
> 
> Nov 28 22:12:56 MyBox postfix/smtp[25840]: E108EE7CA7E: to=<myemail@gmail.com>, relay=gmail-smtp-in.l.google.com[72.14.205.27], delay=1, status=sent (250 2.0.0 OK 1164773309 e15si5530224qba)
> 
> Nov 28 22:12:56 MyBox postfix/qmgr[25431]: E108EE7CA7E: removed
> ...

 

Doing the following while logged in as root does not send an email:

```
MyBox postfix # cat | sendmail -t -i

To: myemail@gmail.com

Subject: testing

```

Yet doing it in one of my local users that have a virtual mailbox associated with them does send it successfully with that.  So I thought that maybe adding the virtual user apache@mydomain.com would help.  But it did not for the php mail() method.

Here is my main.cf file.  I have not tried sending mail through thunderbird yet (my isp blocks port 25 so forced to use their smtp server) but I can recieve mail fine.  And using Squirrelmail I am more than able to send and recieve email which leaves me a bit perplexed because doesn't sendmail also use the php mail() method?

main.cf

```
queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/lib/postfix

mail_owner = postfix

myhostname = mydomain.com

mydomain = mydomain.com

inet_interfaces = all

mydestination =

local_recipient_maps =

unknown_local_recipient_reject_code = 550

mynetworks = 69.xxx.xxx.0/24, 127.0.0.0/8

home_mailbox = .maildir/

local_destination_concurrency_limit = 2

default_destination_concurrency_limit = 20

debug_peer_level = 2

debugger_command =

         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

         xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = /usr/share/doc/postfix-2.2.10/html

manpage_directory = /usr/share/man

sample_directory = /etc/postfix

readme_directory = /usr/share/doc/postfix-2.2.10/readme

message_size_limit = 20480000

mailbox_size_limit = 102400000

smtpd_sasl_auth_enable = yes

smtpd_sasl2_auth_enable = yes

smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes 

smtpd_sasl_local_domain =

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_gid_maps = static:207

virtual_mailbox_base = /var/vmail

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_mailbox_limit = 51200000

virtual_minimum_uid = 207

virtual_mailbox_uid = 207

virtual_transport = virtual

virtual_uid_maps = static:207

smtpd_recipient_restrictions = 

        permit_sasl_authenticated,

        permit_mynetworks,

        reject_unauth_destination,

        permit

smtp_use_tls = yes

smtp_tls_note_starttls_offer = yes

smtpd_use_tls = yes   

smtpd_tls_auth_only = yes

smtpd_tls_key_file = /etc/postfix/newreq.pem

smtpd_tls_cert_file = /etc/postfix/newcert.pem

smtpd_tls_CAfile = /etc/postfix/cacert.pem        

smtpd_tls_loglevel = 3

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

```

Last edited by Soynuts on Thu Nov 30, 2006 3:47 am; edited 1 time in total

----------

## sp7xfq

Hi,

Are you sure that your server does not send mails, because this text,

 *Soynuts wrote:*   

> 
> 
>  *Quote:*   Nov 28 22:12:56 MyBox postfix/smtp[25840]: E108EE7CA7E: to=<myemail@gmail.com>, relay=gmail-smtp-in.l.google.com[72.14.205.27], delay=1, status=sent (250 2.0.0 OK 1164773309 e15si5530224qba)
> 
>  

 

says that mail was sent and was accepted by remote server. 

Maybe gmail blocks your mails, try send an email to my autotest at address mailtest (at) kino.dysk.one.pl

br

----------

## Soynuts

This is the message I got sending to yours.

 *Quote:*   

> Nov 29 07:52:02 MyBox postfix/cleanup[3724]: 51CFEE7CA7E: message-id=<20061129135202.51CFEE7CA7E@mydomain.com>
> 
> Nov 29 07:52:02 UNBUBox postfix/qmgr[3679]: 51CFEE7CA7E: from=<apache@mydomain.com>, size=391, nrcpt=1 (queue active)
> 
> Nov 29 07:52:19 UNBUBox pop3d-ssl: Connection, ip=[75.109.208.103]
> ...

 

I just did a test with an internal virual email address myemail@mydomain.com and the php mail() method sent it to there, though it seemed to have messed up the sender and header fields.  But it sent.  It just does not seem to send properly to outside emails.  I tried my hotmail account but it timed out trying to send to hotmail.

----------

## sp7xfq

Hi, 

It seems that everything is ok. I've received your mail:

```
Nov 29 14:47:55 pocztylion postfix/qmgr[17013]: 18453161D3: from=<apache@YOURS>, size=599, nrcpt=1 (queue active)

Nov 29 14:47:55 pocztylion postfix/local[2595]: 8FA7B162FA: to=<mailtest@MINE>, relay=local, delay=0, status=sent (delivered to command: /usr/bin/procmail)

```

and reply was sent

```

Nov 29 14:47:55 pocztylion postfix/qmgr[17013]: E62E4162F4: from=<mailtest@MINE>, size=603, nrcpt=1 (queue active)

Nov 29 14:48:04 pocztylion postfix/smtp[2605]: E62E4162F4: to=<apache@YOURS>, relay=YOURS[ip.ip.ip.ip], delay=1, status=sent (250 Ok: queued as CBD1CE7CA7B)

```

Unfortunately I can't see your mail, because mailtest@ is only automatic responer and it doesn't keep mails.

Anyway, I think the problem isn't at your side. 

br

----------

## Soynuts

I just did some more searching and apparently Gmail now uses port 465 and not 25, which is what I am using.  When I looked at nmap, it does NOT show any type of service running on port 465 for me.  I followed the gentoo virt-howto for setting up postfix with ssl and all that jazz, but I find it odd that it did not start up anything on port 465 for secure smtp.  I do have pop3d-ssl, imap-ssl, pop3d, imap, and smtp on their appropriate ports but why do I not have anything running on port 465?  Did I miss something in configuration that would start up the service on that port?

----------

## Soynuts

Well, I had several people try the php mail() with their email.  Almost all people got it, only a few did not.  Some gmail people got the email while some gmail people did not which is very weird.  It's good that most are getting the email... but I still would prefer a 100% hit...

Note: it appears that those that did not get the email, the logs show the message as "Queued for delivery"

I also found that I just needed to uncomment two lines in the master.cf file to allow smtps.  However, I get this lovely output in my /var/log/messages

 *Quote:*   

> Nov 29 18:42:09 MyBox postfix/smtpd[19935]: sql_select option missing
> 
> Nov 29 18:42:09 MyBox postfix/smtpd[19935]: auxpropfunc error no mechanism available
> 
> Nov 29 18:42:09 MyBox postfix/smtpd[19935]: _sasl_plugin_load failed on sasl_auxprop_plug_init for plugin: sql
> ...

 

So I've just gone ahead and disabled ssl for the time being as it is just causing more headache.

----------

## Soynuts

Just figured out why I wasn't seeing it in gmail.  It was putting all the messages into the gmail spam folder.  So since I use thunderbird, I never get it since gmail does not send spam to thunderbird...

Any ideas how to prevent my email from being flagged as spam when I send it?

----------

## Soynuts

And figured out why it was listing my email as spam.  Since I run 5 virtual domains with 1 local, I had the local domain set up with reverse lookup.  However, my other 5 (which make much use of the mail() method) send the mail as admin@virtual-domain.com.  So gmail and hotmail see that virtual-domain.com does not have a reverse lookup in my DNS configuration and automatically flags it as spam.  I just added all my virtual domains appropriately for reverse lookup and I no longer have my emails flagged as spam!

----------

## sp7xfq

Hi,

It seems that you've solved almost all postfix problems eventually. Congratulations  :Very Happy: 

About SSL (SMTPS) , you can read Gentoo docs at http://www.gentoo.org/doc/en/virt-mail-howto.xml#doc_chap5 concerning generation of certificates, and if you want to set up your postfix to listen on 465 port, you should add to your master.cf file following lines

```
smtps    inet  n       -       n       -       -       smtpd

         -o smtpd_tls_wrappermode=yes

         -o OTHER SMTP OPTIONS such as content_filter
```

br

----------

## Soynuts

Ya, I added that to the master.cf earlier, but then I had the tls library error above.  I'll probably split that into another topic if I can't figure it out.

----------

## sp7xfq

 *Soynuts wrote:*   

> 
> 
>  *Quote:*   
> 
> Nov 29 18:42:09 MyBox postfix/smtpd[19935]: warning: cannot get private key from file /etc/postfix/newreq.pem
> ...

 

I feel that problem is with SSL certificates files, might /etc/postfix/newreq.pem doesn't exist or doesn't contain SSL's private key.

br

----------

## zxy

@Soynuts: Could you maybe join all the steps you dit to make it work in a small howto, if possible.

----------

## Soynuts

I'm actually still struggling with the spam issue.  However, it only seems to be an issue with gmail and hotmail.  Both have a lot of "extra" stuff they want you to do.  But even then I'm still getting flagged as spam.

Hotmail's Guidelines:

http://postmaster.msn.com/Guidelines.aspx

Gmail's Guidelines:

http://www.google.com/mail/help/bulk_mail.html

I've made an SPF record for my DNS records... but hotmail keeps saying I don't have any...

As for gmail, I haven't tried implementing yahoo's domainkeys yet.

Basically, the biggest thing that will help you from being flagged as spam by everyone else is to make sure you have a reverse DNS that points to your mail server's domain.  Adding an SPF can help as well, which is pretty easy to setup.  http://old.openspf.org/wizard.html helps you create the record.  http://www.gentoo.org/doc/en/mailfilter-guide.xml#doc_chap8 has info on what you need to install to make sure it will work on your server.  Once you have all that you want, use dnsstuff.com to run your domain through some simple tests.

Another tid bit I found in my quest of spam flag checking.  Send an email to the following email address: sales-spamcheck@sitesell.net

For the subject put TEST in all caps.  Nothing in the body.  It may take some time to process, but it will send you back an email and tell you EXACTLY how your email address scores against some of the more common spam checkers.  I scored 0 and 0.2 with several of my tests... yet I get flagged as spam by gmail and hotmail... they are just a pain in the ass which I am about to just stop researching for as most of the common solutions for gmail are: "Get the receipt to add the address to their contact list".  Basically, whitelisting.

----------

