Results 1 to 8 of 8

Thread: php mail() for mere mortals

  1. #1
    Join Date
    Sep 2008
    Location
    Tampa Bay, FL USA
    Beans
    104
    Distro
    Ubuntu 10.04 Lucid Lynx

    php mail() for mere mortals

    I have searched, read, searched again, installed, uninstalled, reinstalled, changed packages, configured php.ini, checked every error log I could imagine and still can not get php's mail() function to work.

    My last attempt was to install exim as a slew of google hits said exim is Ubuntu's preferred sendmail agent.

    Here is my test page
    Code:
    <?php
      $name="Ed Patterson";
      $email = "edpatterson@email.com";
      $recipient = "edpatterson@email.com";
      $mail_body = "This would be the addition report";
      $subject = "URL added to the everyone list";
      $header = "From: ".$name." <".$email.">\n";
      
      mail($recipient, $subject, $mail_body, $header);
      echo "Mail Sent";
    ?>
    my /etc/php5/apache/php.ini file has
    Code:
    sendmail_path = /usr/sbin/sendmail
    Requesting the page from a browser returns
    Mail Sent
    and finally in the syslog
    Code:
    Exim is a Mail Transfer Agent. It is normally called by Mail User Agents, not directly from a shell command line. Options and/or arguments control what it does when called. For a list of options, see the Exim documentation.
    It simply can not be this complicated. I must have missed a very basic step somewhere.

    Ed

  2. #2
    Join Date
    Aug 2008
    Location
    Victoria, BC Canada
    Beans
    1,741

    Re: php mail() for mere mortals

    Exim and postfix are MTA programs, and I invoke spamming via sendmail.

    Mind you I also have dovecot on the machine too.

  3. #3
    Join Date
    Dec 2006
    Location
    Chicago
    Beans
    3,839

    Re: php mail() for mere mortals

    I use postfix. Give that a try
    Code:
    sudo apt-get install postfix
    If you still have problems, check the log
    Code:
    tail /var/log/mail.log
    It could simply be getting blocked as spam based on your dns configuration.
    Exim and postfix are MTA programs, and I invoke spamming via sendmail.
    You're a spammer?

  4. #4
    Join Date
    Sep 2008
    Location
    Tampa Bay, FL USA
    Beans
    104
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: php mail() for mere mortals

    Well, I installed postfix but I do not think it is what I am looking for. Or perhaps it is not the best tool for what I want to do.

    The server is used from proxy filtering. Squid blocks request, sends user to a php page where they may request it. If/When the request it it is added to a MySQL database and the white lists are regenerated. I would like to recieve an email too. I figured this would be a one liner and it is in php, it is getting something/anything to send the message out that is the problem.
    Code:
    postfix/master[12314]: fatal: bind 0.0.0.0 port 25: address already in use
    followd a few minutes later after attempting to send a message via php
    Code:
    sm-mat[12651]: NOQUEUE: SYSERR(root): hash map "access": missing map file /etc/mail/access.db: No such file or directory
    I already have an smtp server that will pass mail for this server if I can figure out how to get it there.

    Thanks,
    Ed

  5. #5
    Join Date
    Dec 2006
    Location
    Chicago
    Beans
    3,839

    Re: php mail() for mere mortals

    Apparently you already have a server running on port 25, so postfix won't start.
    Code:
    sudo lsof -i :25

  6. #6
    Join Date
    Sep 2008
    Location
    Tampa Bay, FL USA
    Beans
    104
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: php mail() for mere mortals

    <much reading, testing has passed>
    I have installed postfix and mailx which claimed to have uninstalled sendmail. 'ps aux | grep mail' showed sendmail was still running. I killed the process, accessed my mailtest.php page. It reported success (1). /val/log/mail.err reports no errors. The message was not received by any of the accounts. The email accounts here are of course not the ones I used.
    Code:
    <?php
      $to = "ed_patterson@adress1, edpatterson@address2, pattersoned@address3";
      $subject = "Mail from Ubuntu PHP";
      $message = "The message, $subject, was sent to $to\n";
      echo mail($to,$subject,$message)."<br>\n";
      echo "Did it go (this is from Ubuntu)?<br>\n";
     ?>
    Perplexed I installed XAMPP on a thumbdrive under Windows, configured PHP for my external smtp server, used the same php page and all 3 accounts received the message so I am fairly certain the PHP stuff is right.

    I am at a loss where to go next. I tried to find the postfix 'outbox' for lack of a better term and failed. I can only assume the message(s) is stuck some where on my Ubuntu box waiting for something to deliver it.

    Ed

  7. #7
    Join Date
    Mar 2007
    Location
    Hillsboro, OR
    Beans
    169
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: php mail() for mere mortals

    you can try sudo postqueue -p to view messages that are queued and waiting to go out. You can also look at /var/log/mail.log to see if it's reporting anything leaving.
    Apollo(ss): Ubuntu 8.10, Pentium T2330, 2GB RAM, 200GB(Laptop)
    Hestia: Ubuntu 8.04.1, 2.4Ghz P4, 1GB RAM, 500GB, (SMB/FTP/Torrent) {Rebuilding}
    Poseidon: Ubuntu Server 8.04.1, 512MB, LAMP, Mail (VPS)

  8. #8
    Join Date
    Sep 2008
    Location
    Tampa Bay, FL USA
    Beans
    104
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: php mail() for mere mortals

    Fixed!
    I had to edit the php.ini file
    sendmail_path = /usr/sbin/sendmail -t -i -f servername@domain.com (space between the -f and address is important)

    Discovered this by reading /var/log/mail.info. Mail was leaving my system from www-data@domain.com
    I also learned that it is a good idea to restart apache after editing the php.ini file...

    Thanks to all for the help!
    Ed

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •