Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 = 127.0.0.0/8 [::ffff:127.0.0.0]/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

/etc/postfix/sasl_password:

my.providers.smtp my_login:my_password

/etc/postfic/sender_canonical:

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).

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
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.

<?php
     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 http://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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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