Setting up a Ubuntu/Apache/PHP machine to send email

70,558

Solution 1

sudo apt-get install sendmail will install a copy of sendmail that listens locally. If you install that, then php can use the built in mail() function. There also won't be a risk of becoming a remote relay if you install like this as well.

If you plan on sending mail out to other internet domains, you will need to make sure the IP address of the machine sending mail has a reverse DNS entry (PTR record) set up as well. Most large ISP's will reject your mail if your IP does not have a PTR record or one that points to a generic host (e.g. 1.2.3.3.domain.isp.com). It should reverse to something like mail.yourdomain.com

Solution 2

The native mail function is a good built-in option.

The mail function is part of the PHP core, but it does require sendmail to be installed on the server.

I believe sendmail might already be installed with the packages you have already selected, but you can check for it using the command:

dpkg --get-selections | grep sendmail

If that comes up empty, you can install sendmail with:

sudo apt-get install sendmail

Solution 3

sudo apt-get install sendmail
sudo sendmailconfig

The second command was needed for me to run correctly. (it asks about some configuration, just type Y everytime it asks)

Solution 4

I recommend installing Postfix MTA to send e-mails out the Ubuntu server:

aptitude install postfix

And using the PHP Mailer class to send e-mails from PHP: http://phpmailer.worxware.com/


For "fully featured" e-mail services my recipe is:

Postfix + DKIM-proxy + Dovecot + Roundcube + PHP Mailer + SpamAssassin + proper DNS settings + SSL certificate to enable encrypted connections

(And I prefer NginX as HTTP server...)

Solution 5

sendmail does the trick. You can configure sendmail to use your regular email smtp account, details are here: http://developernote.com/2012/07/how-i-configured-sendmail-for-php-on-ubuntu-server-12-04/ and specifically for gmail here: http://linuxconfig.org/configuring-gmail-as-sendmail-email-relay There is a bug in the sendmail configuration files which you can read about here: http://linux.koolsolutions.com/2010/10/14/tip-fixing-sendmail-configuration-error/

Share:
70,558
Dương Văn
Author by

Dương Văn

Updated on July 09, 2020

Comments

  • Dương Văn
    Dương Văn almost 4 years

    I am working for a small Ho Chi Minh City company whose only server was just one old small computer. Now just a few months later, we are expanding rapidly and one of the requirements for new users is to require them to verify their email addresses.

    There are no special programs on the Ubuntu box, instead the only thing I did on the actual server was re-format the entire hard drive from windows XP and installed Natty Narwhal on it, then install Apache and PHPMYADMIN.

    I would like to have PHP to send out an email to both the user and the administrators as soon as somebody applies for membership. But I have no idea what I need to do to start.

    Any ideas on what I need to set up first would be humbly appreciated; I am not looking for a step by step, just some tips to point me in the right direction.

    -Duong Van

  • Dương Văn
    Dương Văn over 12 years
    Thank you, I will search for that package.
  • Sliq
    Sliq almost 11 years
    Perfect answer, and it's unbelievable that this is NOT EXPLAINED ANYWHERE !!! I'm trying for WEEKS now to send a mail with php.
  • Jonathan Brown
    Jonathan Brown almost 11 years
    +1 for noting that sendmail must be installed for the mail() function! No other site I had come across yet mentioned that
  • AlexR
    AlexR almost 11 years
    Thank you very much, you saved me hours of searching!
  • Goose
    Goose over 8 years
    "The native mail function is a good built-in option.". I have to disagree. There's too many gotchas, and using a library is much easier and more reliable.
  • Luka Govedič
    Luka Govedič almost 8 years
    Could you please explain how to do the thing explained in the second paragraph? Thanks!
  • drew010
    drew010 almost 8 years
    @LukaGovedič In most cases you have to call your ISP to configure this for you. Few have tools to set this up depending on your provider. Also, you need a static IP, so if you're doing this on your home connection it has to be static IP service. I've seen some hosting providers that assign you a dedicated IP have web tools to set up your own reverse dns so it may be in your hosting control panel if it's on a hosted service.
  • Alessandro Mascolo
    Alessandro Mascolo over 6 years
    The link is outdated, now sends to illegal content