testing php mail function

January 27, 2015 9.5k views

I have installed sendmail and trying to use a basic mail function in a php page that works on another server.

Have tried a few command line test emails that both worked fine. Successful tests:

```Created a txt file, then used sendmail -v peter@myemail.com < mail.txt

that worked, then I tried...

echo "this is email body"|mail -s "This is email subject" peter@myemail.com

which also worked fine


However, the PHP mail function is dead. The only thing I've come across that seemed odd were some error message during the sendmail install process:

Creating /etc/mail/sendmail.cf...
*** ERROR: FEATURE() should be before MAILER()
*** MAILER(local') must appear after FEATURE(alwaysadddomain')*** ERROR: FEATURE() should be before MAILER()
*** MAILER(local') must appear after FEATURE(allmasquerade')*** ERROR: FEATURE() should be before MAILER()

Creating /etc/mail/submit.cf...
Informational: confCRFILE file empty: /etc/mail/relay-domains
Informational: confCT
FILE file empty: /etc/mail/trusted-users
Updating /etc/mail/access...
Updating /etc/mail/aliases...
/etc/mail/aliases: 1 aliases, longest 4 bytes, 14 bytes total

Warning: These messages were issued while creating sendmail.cf
make sure they are benign before starting sendmail!

Errors in generating sendmail.cf
*** ERROR: FEATURE() should be before MAILER()
*** MAILER(local') must appear after FEATURE(alwaysadddomain')*** ERROR: FEATURE() should be before MAILER()
*** MAILER(local') must appear after FEATURE(allmasquerade')*** ERROR: FEATURE() should be before MAILER()


Any ideas? I've googled 'test php mail function' and read through numerous posts but nothing seemed to work or fit with my context... Ubuntu 14/Nginx/PHP.
8 comments
  • try running:

    sudo sendmailconfig
    

    just accept the defaults...reboot..try again

  • Tried that and got these errors:

    Warning: These messages were issued while creating sendmail.cf
        make sure they are benign before starting sendmail!
    
    Errors in generating sendmail.cf
    *** ERROR: FEATURE() should be before MAILER()
    *** MAILER(`local') must appear after FEATURE(`always_add_domain')*** ERROR: FEATURE() should be before MAILER()
    *** MAILER(`local') must appear after FEATURE(`allmasquerade')*** ERROR: FEATURE() should be before MAILER()
    
    
  • You messed up your sendmail config file, check if there is any backup like sendmail.cf.bak or similar and restore, then restart sendmail.

    You never edit sendmail.cr edit sendmail.mc and run make to create the config file. Sure thing this is different for every system so look for a sendmail guide for your current OS.

    Best of luck

  • Hey @EpicCDN I completely uninstalled and reinstalled and its the same thing all over again. I'm not sure what you mean by "messed up my sendmail config file" when all I did was answer Y to the three or four questions during install. Since yes is always the default, what could I have done wrong?

    Anyway, I can't find any setup guides for sendmail/ubuntu/nginx. I AM able to confirm that sendmail works via this command line:

    echo "My test email being sent from sendmail" | /usr/sbin/sendmail me@you.net
    

    However, still no luck with my php pages using the mail command. Tried searching for php configuration guides for ubuntu/nginx but no luck.

  • @peter742544 the error looks like the sendmail config file sendmail.cf is incorrect, that's why I tough you maybe was manually messing around with the file, but if not the case then something is wrong with the package. I'm not sure about ubuntu, but you should try to update the package repo and install again sendmail.

    Also you can skip sendmail at all and use mandrill to send your php emails, it has a really easy to use API that you can use both per script or into php.ini (global) and offers you a great way to manage and monitor your emails.

    Check it at mandrillapp.com is free up to 12k email per month, and extra emails are really cheap, but 12k is a lot.

  • @EpicCDN Where do the packages come from? Wouldn't they automatically be grabbing the latest version upon install, especially if my system is up to date? (Forgive my ignorance.)

    Yeah, already using Mandrill for my wordpress install when I couldn't get mail stuff working last year. Didn't think using a single line script in a php page was going to cause such an endless whirlpool of cascading frustration.

  • Repos not always use the latest packages, just the latest ones tested and compatible with your OS version, in theory they should be working, but one never knows.

    Sendmail is ready to use once installed, so if yours is not working something must be very wrong.

    You should try configuring php to globally use mandrill, managing MTA's like postfix or sendmail is ALWAYS a pain in the ass, today is the setup, tomorrow spam problems, is a never ending problem.

  • Thanks for the advice @EpicCDN but looks like I'll have to wait until I can hire a developer as both scenarios (troubleshooting the PHP failure + the Mandrill API) are totally over my head.

    Appreciate you taking the time to try to help me. :-)