sending e-mail using mail() function

Discussion in 'HOWTO-Related Questions' started by linuxuser1, Apr 21, 2006.

  1. linuxuser1

    linuxuser1 New Member

    How can i set up my debian servers - one with postfix and 1 with sendmail to allow a php script to use the mail() function to send e-mail. Both servers have ISPConfig installed.

    What i have in my php.ini =
    ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = /usr/sbin/sendmail

    The php.ini is located at /etc/php4/apache2/php.ini


    Thanks
     
    Last edited: Apr 21, 2006
  2. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    The mail() function should work out of the box. You don't have to configure anything.
     
  3. linuxuser1

    linuxuser1 New Member

    Hi Falko,

    The problem is I have 2 scripts and non of them works. I have vbulletin and 2 other ones. For Vbulleting I have to ask it to use smtp before it can work. For one of the other scripts I also have to specify an SMTP before it can work just like VBulletin but for the other one, there is no where to set an SMTP and I have been trying to get it to work with no progress which is why I
    have to uncomment as sendmail_path = /usr/sbin/sendmail thinking this will help but unfortunately it still does not work.

    Thanks as always.
     
  4. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    How did you install PHP? Did you compile it from the sources, or did you install your distribution's preconfigured packages? Do you have Postfix or Sendmail installed?
     
  5. linuxuser1

    linuxuser1 New Member

    Hi Falko,

    I used your debian perfect set up - (http://www.falkotimme.com/howtos/perfect_setup_debian_sarge/index.php) to install both servers. I used your sendmail perfect set up to install sendmail (http://www.falkotimme.com/howtos/sendmail_smtp_auth_tls/index.php )and both servers have Ispconfig working very well. I used your perfect setup to install Postfix on another one. When I tried using the mail() function in Postfix and it did not work, I then went to try sendmail and its still the same problem.

    Should the mail() function work right away after following your perfect setup or i should have done something else tomake it work.

    Please help and many thanks.
     
  6. sjau

    sjau Local Meanie Moderator HowtoForge Supporter

    For testing I would suggest to use the mail() examples in the php doc. If they don't work then there's some issue:

     
  7. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    It should work right away. Do you get errors when you use the mail() function (also look in the mail log)?
     
  8. linuxuser1

    linuxuser1 New Member

    Hello Falko,

    Mail log as requested

    Apr 24 22:59:36 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 24 22:59:36 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 24 22:59:36 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: server SMTP socket wedged: exiting
    Apr 24 23:17:21 mailx sendmail[1678]: NOQUEUE: SYSERR(www-data): can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=0, required=1001): Permission denied
    Apr 25 00:00:04 mailx authdaemond.plain: restarting authdaemond children
    Apr 25 00:00:04 mailx authdaemond.plain: modules="authpam", daemons=5
    Apr 25 00:01:09 mailx authdaemond.plain: modules="authpam", daemons=5
    Apr 25 00:01:13 mailx sendmail[1273]: starting daemon (8.13.6): SMTP+queueing@01:00:00
    Apr 25 00:01:13 mailx sendmail[1273]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:13 mailx sendmail[1273]: daemon MTA: problem creating SMTP socket
    Apr 25 00:01:15 mailx sendmail[1307]: k3ON1FvG001307: from=root, size=1567, class=0, nrcpts=1, msgid=<200604242301.k3ON1FvG001307@mailx.cjahosting.com>, relay=root@localhost
    Apr 25 00:01:15 mailx sendmail[1307]: k3ON1FvG001307: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31567, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (OK id=1FYA3P-0000L6-IM)
    Apr 25 00:01:18 mailx sendmail[1273]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:18 mailx sendmail[1273]: daemon MTA: problem creating SMTP socket
    Apr 25 00:01:23 mailx sendmail[1273]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:23 mailx sendmail[1273]: daemon MTA: problem creating SMTP socket
    Apr 25 00:01:38 mailx sendmail[1273]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:38 mailx sendmail[1273]: daemon MTA: problem creating SMTP socket
    Apr 25 00:01:48 mailx sendmail[1273]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:48 mailx sendmail[1273]: daemon MTA: problem creating SMTP socket
    Apr 25 00:01:48 mailx sendmail[1371]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:48 mailx sendmail[1371]: daemon MTA: problem creating SMTP socket
    Apr 25 00:01:53 mailx sendmail[1273]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:01:53 mailx sendmail[1273]: daemon MTA: problem creating SMTP socket
    Apr 25 00:02:13 mailx sendmail[1371]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:02:14 mailx sendmail[1371]: daemon MTA: problem creating SMTP socket
    Apr 25 00:02:14 mailx sendmail[1371]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: server SMTP socket wedged: exiting
    Apr 25 00:08:05 mailx authdaemond.plain: restarting authdaemond children
    Apr 25 00:08:05 mailx authdaemond.plain: modules="authpam", daemons=5
    Apr 25 00:09:13 mailx authdaemond.plain: modules="authpam", daemons=5
    Apr 25 00:09:17 mailx sendmail[1272]: starting daemon (8.13.6): SMTP+queueing@01:00:00
    Apr 25 00:09:17 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:17 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:22 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:22 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:32 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:32 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:36 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:36 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:37 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:37 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:41 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:41 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:42 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:42 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:46 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:46 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:47 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:47 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:51 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:51 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:52 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:52 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:56 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:56 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:09:57 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:09:57 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:01 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:10:01 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:02 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:10:02 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:06 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:10:06 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:07 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:10:07 mailx sendmail[1272]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:07 mailx sendmail[1272]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: server SMTP socket wedged: exiting
    Apr 25 00:10:11 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:10:11 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:16 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
    Apr 25 00:10:16 mailx sendmail[1358]: daemon MTA: problem creating SMTP socket
    Apr 25 00:10:16 mailx sendmail[1358]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: server SMTP socket wedged: exiting
    Apr 25 00:16:30 mailx sendmail[1636]: NOQUEUE: SYSERR(www-data): can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=0, required=1001): Permission denied
    Apr 25 00:22:11 mailx courierpop3login: Connection, ip=[::ffff:127.0.0.1]
    Apr 25 00:22:11 mailx courierpop3login: LOGIN, user=web1_alpharadiotv, ip=[::ffff:127.0.0.1]
    Apr 25 00:22:11 mailx courierpop3login: LOGOUT, user=web1_alpharadiotv, ip=[::ffff:127.0.0.1], top=0, retr=0, time=0
    Apr 25 00:22:48 mailx courierpop3login: Connection, ip=[::ffff:127.0.0.1]
    Apr 25 00:22:48 mailx courierpop3login: LOGIN, user=web1_alpharadiotv, ip=[::ffff:127.0.0.1]
    Apr 25 00:22:48 mailx courierpop3login: LOGOUT, user=web1_alpharadiotv, ip=[::ffff:127.0.0.1], top=0, retr=0, time=0


    Thanks
     
  9. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    You have a problem with Sendmail, not with PHP's mail() function.
    What's the output of
    Code:
    netstat -tap
    ?
     
  10. linuxuser1

    linuxuser1 New Member

    mailx:~# netstat -tap
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 *:imaps *:* LISTEN 1 103/couriertcpd
    tcp 0 0 *:pop3s *:* LISTEN 1 126/couriertcpd
    tcp 0 0 localhost.localdo:mysql *:* LISTEN 1 220/mysqld
    tcp 0 0 *:pop3 *:* LISTEN 1 112/couriertcpd
    tcp 0 0 *:imap2 *:* LISTEN 1 089/couriertcpd
    tcp 0 0 *:www *:* LISTEN 1 352/apache2
    tcp 0 0 *:81 *:* LISTEN 1 319/ispconfig_http
    tcp 0 0 *:ftp *:* LISTEN 1 397/proftpd: (acce
    tcp 0 0 virtual-ip1.cjah:domain *:* LISTEN 1 382/named
    tcp 0 0 europa.cjahostin:domain *:* LISTEN 1 382/named
    tcp 0 0 localhost.locald:domain *:* LISTEN 1 382/named
    tcp 0 0 *:ssh *:* LISTEN 1 280/sshd
    tcp 0 0 localhost.localdoma:953 *:* LISTEN 1 382/named
    tcp 0 0 localhost.localdom:smtp *:* LISTEN 1 160/exim4
    tcp 0 0 *:https *:* LISTEN 1 352/apache2
    tcp 0 0 virtual-ip1.cjahost:www cjahosting.plus.co:7161 FIN_WAIT2 2223/apache2
    tcp 0 2076 europa.cjahosting.c:ssh 192.168.21.18:2450 ESTABLISHED6702/0
    mailx:~#


    Thanks so much.
     
  11. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    You have Exim installed, not Sendmail or Postfix... :confused:
     
  12. Nap

    Nap Member

    Since I'm new to Linux, I'm not sure if I have SendMail running on this machine. Here is my NetStat -tap output.

    Based on the info below, do I need to install Sendmail in order to use the PHP email() function?

    Cheers,
    Nap

    Code:
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State PID/Program name
    tcp        0      0 *:mysql                 *:*                     LISTEN     2 1327/mysqld
    tcp        0      0 *:sunrpc                *:*                     LISTEN     2 166/portmap
    tcp        0      0 *:81                    *:*                     LISTEN     1 1021/ispconfig_htt
    tcp        0      0 *:ftp                   *:*                     LISTEN     1 1189/proftpd: (acc
    tcp        0      0 *:smtp                  *:*                     LISTEN     3 1715/master
    tcp        0      0 localhost.localdoma:670 *:*                     LISTEN     3 038/famd
    tcp6       0      0 *:imaps                 *:*                     LISTEN     2 734/couriertcpd
    tcp6       0      0 *:pop3s                 *:*                     LISTEN     2 755/couriertcpd
    tcp6       0      0 *:pop3                  *:*                     LISTEN     2 742/couriertcpd
    tcp6       0      0 *:imap2                 *:*                     LISTEN     2 721/couriertcpd
    tcp6       0      0 *:www                   *:*                     LISTEN     1 1052/apache2
    tcp6       0      0 *:ssh                   *:*                     LISTEN     3 034/sshd
    tcp6       0      0 *:smtp                  *:*                     LISTEN     3 1715/master
    tcp6       0      0 *:https                 *:*                     LISTEN     1 1052/apache2
    
    
     
  13. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    You have Postfix installed:
    master is a Postfix process.

    You don't need to have Sendmail installed to use PHP's mail() function, any SMTP server (like Postfix) is fine. :)
     
  14. Nap

    Nap Member

    Thanks. Wasn't sure, since the PHP manual says that the mail() function requires sendmail.

    Cheers,
    Nap
     
  15. rosy

    rosy New Member

    php and mail

    Hi,
    I used mail command as command line argument and it works fine to send email to my mailbox . If i try using php mail() command its not working, i have no errors encountered. In the program if i use phpinfo(),
    sendmail_from has no values set
    sendmail_path has no values set
    smtp is set to localhost
    smtp_port is set to 25.
    I think this might be the problem , how do i need to fix it.
    Please help.
    Thanks.
     
  16. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    What's in your mail log when this happens?
     
  17. rosy

    rosy New Member

    In my mail log /var/log/exim/mainlog
    2006-11-17 09:38:01 Start queue run: pid=4326
    2006-11-17 09:38:01 End queue run: pid=4326
    This is in my mail log.
    What might be the problem.please help.
     
  18. Nap

    Nap Member

    Rosy,
    Can you post some of your code that you're using to send the mail?
    Cheers,
    Nap
     
  19. rosy

    rosy New Member

    thanks a lot and php mail problem is solved.
    It works for me.
    Thanks again:)
     
  20. ataman79

    ataman79 New Member

    Hi I have same problem, I have Debian with postfix, when I type
    sendmail - t .... I received email to my mailbox. But now I try to use a php script for sending mails and don't receive any mails (the script is working on other servers) I'm using php mail() function.

    Where can be the problem ??

    Thank you in advanced!
     

Share This Page