I've been trying for 2 whole days now, and I just can't get the most simple thing to work.

The problem: Sending eMails from PHP to my eMail address does not work

I've been working with Windows and Sendmail (Sendmail was within the XAMPP package) before and everything was OK. The XAMPP-package (1.7.7) for Linux doesn't have Sendmail integrated though. So after googling around a little I found out that Postfix fits better into a LAMPP-environment.

What I have tried so far:

I've installed Postfix and wanted to configure it to just use the smtp-server of my private eMail provider (like it did on Windows). So I've confogured my php.ini like this:

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

sendmail_path = /etc/postfix
mail.add_x_header = On

Note that I've commented out the "Win32 only"-stuff. The /etc/postfix/main.cf Looks like this:

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
myhostname = ubuntu
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
sender_canonical_maps = hash:/etc/postfix/sender_canonical
mydestination = ubuntu, localhost.localdomain, localhost
relayhost = mail.gmx.net
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only

/etc/aliases is unchanged:

# Required aliases
postmaster: root
MAILER-DAEMON:  postmaster

# Common aliases
abuse:      postmaster
spam:       postmaster


my.providers.smtp my_login:my_password


postmaster my.email@ddress.com

What happens:

So when I do

> sudo /etc/init.d/postfix start

everything seems to work fine and the /var/log/mail.log says: "ubuntu postfix/master[9720]: daemon started -- version 2.8.5, configuration /etc/postfix"

But when I run my PHP-script (which worked fine with Windows and Sendmail), it just runs through and nothing happens, not even an error is logged.

What I actually want to achieve:

I'm working locally on an e-commerce website. It runs fine on the dedicated webserver, but I want to also have it running locally for obvious reasons. In some cases, it sends emails, and I just want to be able to receive them with Thunderbird or in any other way. Is using Postfix overkill here? I don't need to receive emails - I just want to make the sent mails visible somehow. I could not seem to find any helpful step-by-step-tutorials for this issue (neither concerning Senmail nor Postfix - but, to be honest, I'm very new to Linux).


In your php.ini, this:

sendmail_path = /etc/postfix

Should be the path to the sendmail (or compatible) binary.
You've set it to the configuration directory of postfix which isn't right.

For historical reasons, usually /usr/bin/sendmail is maintained as a compatibility link.
sendmail was around first (I guess) and pretty much everything just assumes it is in the installed MTA. So when it isn't, the replacement makes a symlink so that nothing breaks.

  • Thank you soooo much! Even though I don't quite understand why and in what way Sendmail and Postfix work together - it works now! Can't remember where I read about setting it to postfix, but this is the correct setting in my case: sendmail_path = "/usr/sbin/sendmail -t -i" – Quasdunk Dec 15 '11 at 23:35
  • Added a little more info - basically they're not working together as such, you don't have sendmail, but postfix is pretending to be, because so much stuff expects it to be there :) You could equally set the sendmail_path to point at the postfix binary. – Caesium Dec 15 '11 at 23:56
  • 1
    I remember! sendmail had bug after bug after bug after bug for years on end. At one point, you could include a root-only command in your ~/.forward, send yourself a mail, and do whatever on a Unix/Linux system. There was mass Exodus, and new mail servers included a sendmail-like program designed to behave like sendmail so that all of the other programs which had built themselves around sendmail would still work with no additional effort. – user8290 Dec 16 '11 at 0:55
  • Thanks a lot for the additional information! It all makes more sense now ;) I'd give you another +1 if I could, but I hope someone else who finds this just as helpful will do it for me :-D – Quasdunk Dec 16 '11 at 9:58

To send mail from localhost (WAMP, XAMP, or LAMP) you can use PHPMailer package

This will be same instruction given in readme file..

WAMP (windows):

First you have to edit the "php.ini" To find this file display the phpinfo by using following code from the WAMP server. Create one php file [setting.php] inside C:/wamp/www/ and add the following content to that file.

     echo phpinfo();

Type localhost/setting.php at browser. There search for "Loaded Configuration File" That will be the path to your php.ini.

In php.ini file remove the ;(semi colon) given to `extension=php_openssl.dll. Now server setting is over...

  • After downloading PHPMailer folder from github,
  • Extract->Copy the full folder into your project folder i.e C:/wamp/www/
  • Find the index.php file.
  • Change the parameter as your need.
  • Then in the browser type localhost/PHPMailer/index.php.
  • Then it will show successful message if email sent, else it will give error message.

LAMP (Linux):

  • In case of linux, There is no need to edit the php.ini file as i explained first point under WAMP.

  • One more change is project or Document root folder is different.

  • In Linux the default Document root folder will be /var/www
  • You can change the Document root folder easily. For that visit https://stackoverflow.com/a/17612396/1925943
  • Copy the PhpMailer to this document root folder and edit index.php as your need.
  • Then type localhost/PhpMailer/index.php in browser.

To send email (with sendmail package) through Gmail from localhost please check PHP+Ubuntu Send email using gmail form localhost is possible another answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.