sending e-mail using mail() function

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

  1. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    Any errors in your mail log or in Apache's error log? Are you using PHP Safe Mode?
     
  2. ataman79

    ataman79 New Member

    Yes I have an error in my apache's error log:

    [Wed Jul 09 17:24:48 2008] [error] an unknown filter was not added: PHP
    sendmail: fatal: Recipient addresses must be specified on the command line or via the -t option
    [Wed Jul 09 17:24:48 2008] [error] an unknown filter was not added: PHP
    [Wed Jul 09 17:24:48 2008] [error] an unknown filter was not added: PHP


    And this is the error which I have in my mail.log:

    Jul 9 17:24:48 mailserver postfix/sendmail[26585]: fatal: Recipient addresses must be specified on the command line or via the -t option
     
    Last edited: Jul 9, 2008
  3. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    http://www.howtoforge.com/forums/showthread.php?t=2165&highlight=$go_info["server"]["apache2_php"]


    Did you specify a recipient in the mail command?
     
  4. ataman79

    ataman79 New Member


    Yes I did, here is the script I'm using

    PHP:
    <?
    /* Edit these preferences to suit your needs */

      
    $mailto 'myemailaddress@domain.com'// insert the email address you want the form sent to
        
    $returnpage 'thankyou.php'// insert the name of the page/location you want the user to be returned to
        
    $sitename 'Anatoly-art'// insert the site name here, it will appear in the subject of your email

    /* Do not edit below this line unless you know what you're doing */
        
      
    $name $_POST['name'];
      
    $tel $_POST['tel'];
      
    $email $_POST['email'] ;
      
    $enquiry stripslashes($_POST['query']);

        if (!
    $name) {
            
    open("<strong>Error:</strong> Please provide your name.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
             exit;
        }
        if (!
    $tel) {
            print(
    "<strong>Error:</strong> Please provide your telephone number.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
             exit;
        }
        if (!
    eregi("[0-9]{5,25}"$tel)){
        print(
    "<strong>Error:</strong> Telephone number must include: country code + area code + telephone number<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
             exit;
        }
        if (!
    $email) {
            print(
    "<strong>Error:</strong> Please provide a valid email address.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
             exit;
        }
        if (!
    $enquiry) {
            print(
    "<strong>Error:</strong> Please provide your enquiry details.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
             exit;
        }
        if (!
    eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}"$email)){
        print(
    "<strong>Error:</strong> this email address is not in a valid format.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
             exit;
        }    

      
    $message "\n$name submitted the following message:\n\n$enquiry\n\nTheir contact details are as follows:\n\nName: $name\nTelephone: $tel\nEmail Address: $email\n";

      
    mail($mailto"$sitename Contact Form from $name"$message"From: $email");
        
    header("Location: " $returnpage);
    ?>

     
  5. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    What's in the mail section of your php.ini?
     
  6. ataman79

    ataman79 New Member

    This is thr mail section of my php.ini , which is located in /etc/php5/apache2/php.ini - you mean this file right ?


    [Syslog]
    ; Whether or not to define the various syslog variables (e.g. $LOG_PID,
    ; $LOG_CRON, etc.). Turning it off is a good idea performance-wise. In
    ; runtime, you can define these variables by calling define_syslog_variables().
    define_syslog_variables = Off

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

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

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

    ; Force the addition of the specified parameters to be passed as extra parameters
    ; to the sendmail binary. These parameters will always replace the value of
    ; the 5th parameter to mail(), even in safe mode.
    ;mail.force_extra_parameters =
     
  7. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    Try
    Code:
    sendmail_path = /usr/sbin/sendmail -t
    and comment out the SMTP and smtp_port lines. Restart Apache afterwards.
     
  8. ataman79

    ataman79 New Member


    Thank you Falko, you always help me ! Now all is OK !!! :)
     
  9. misiek04

    misiek04 New Member

    Hi.
    I`ve got the similar problem, but in my case i can`t send message to other server. If I send e-mail to my domain it works good and no error message in log.
    While sending to other domain in log I have got:

    Sender address rejected: Domain not found (in replay to MAIL FROM command)

    When I use IMAP to send e-mail to other domains everything works good.
     
  10. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    Is this other domain on another or on your server?
     
  11. misiek04

    misiek04 New Member

    Send to another server. I solve this problem. In /etc/mailname change hostname.mydomain.com to mydomain.com. Now everything works.
     
  12. ParDust

    ParDust New Member

    mail() and pop3 error

    Hi i just setup my debian server as mentioned in http://www.howtoforge.com/perfect_setup_debian_etch

    All services are on however when i try to send email via php's mail() function i get some errors on mail.log like,

    Oct 4 16:23:06 server postfix/smtp[3722]: 186A06443EB: host f.mx.mail.yahoo.com[209.191.88.247] refused to talk to me: 553 Mail from xx.xxx.xxx.xx not allowed - 5.7.1 [BL21] Connections not accepted from IP addresses on Spamhaus PBL; see http://postmaster.yahoo.com/550-bl21.html [550]". mail() function works, it sends the message however recipient blocks message.

    Thus my server is in my local network behind an adsl router, when i try to connect to pop3 service via client Kmail 1.9.10 i get those error below on mail.log, what went wrong?

    Oct 4 16:23:11 server courierpop3login: Connection, ip=[::ffff:127.0.0.1]
    Oct 4 16:23:11 server courierpop3login: Disconnected, ip=[::ffff:127.0.0.1]
    Oct 4 16:23:11 server postfix/smtpd[3741]: connect from localhost.localdomain[127.0.0.1]
    Oct 4 16:23:11 server postfix/smtpd[3741]: lost connection after CONNECT from localhost.localdomain[127.0.0.1]
    Oct 4 16:23:11 server postfix/smtpd[3741]: disconnect from localhost.localdomain[127.0.0.1]
    Oct 4 16:23:19 server postfix/trivial-rewrite[3721]: table hash:/etc/postfix/virtusertable(0,lock|fold_fix) has changed -- restarting
    Oct 4 16:23:31 server postfix/smtpd[3741]: table hash:/etc/postfix/virtusertable(0,lock|fold_fix) has changed -- restarting
    Oct 4 16:23:31 server courierpop3login: Connection, ip=[::ffff:127.0.0.1]
    Oct 4 16:23:31 server courierpop3login: Disconnected, ip=[::ffff:127.0.0.1]
    Oct 4 16:23:31 server postfix/smtpd[4026]: connect from localhost.localdomain[127.0.0.1]
    Oct 4 16:23:31 server postfix/smtpd[4026]: lost connection after CONNECT from localhost.localdomain[127.0.0.1]
    Oct 4 16:23:31 server postfix/smtpd[4026]: disconnect from localhost.localdomain[127.0.0.1]

    telnet localhost 25 output:

    server:/var/log# telnet localhost 25
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    220 server.xxx.org ESMTP Postfix (Debian/GNU)
    ehlo localhost
    250-server.xxx.org
    250-PIPELINING
    250-SIZE 10240000
    250-VRFY
    250-ETRN
    250-STARTTLS
    250-AUTH PLAIN LOGIN
    250-AUTH=PLAIN LOGIN
    250-ENHANCEDSTATUSCODES
    250-8BITMIME
    250 DSN
    quit
    221 2.0.0 Bye
    Connection closed by foreign host.

    command: "netstat -tap" ouput:

    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 *:43332 *:* LISTEN 2463/rpc.statd
    tcp 0 0 *:mysql *:* LISTEN 5605/mysqld
    tcp 0 0 *:sunrpc *:* LISTEN 2102/portmap
    tcp 0 0 *:81 *:* LISTEN 31794/ispconfig_htt
    tcp 0 0 *:auth *:* LISTEN 2429/inetd
    tcp 0 0 server.xxx.org:domain *:* LISTEN 3469/named
    tcp 0 0 localhost.locald:domain *:* LISTEN 3469/named
    tcp 0 0 *:ftp *:* LISTEN 32146/proftpd: (acc
    tcp 0 0 localhost.localdoma:953 *:* LISTEN 3469/named
    tcp 0 0 *:smtp *:* LISTEN 1651/master
    tcp6 0 0 *:imaps *:* LISTEN 7538/couriertcpd
    tcp6 0 0 *:pop3s *:* LISTEN 7458/couriertcpd
    tcp6 0 0 *:pop3 *:* LISTEN 7401/couriertcpd
    tcp6 0 0 *:imap2 *:* LISTEN 7491/couriertcpd
    tcp6 0 0 *:www *:* LISTEN 3213/apache2
    tcp6 0 0 *:ssh *:* LISTEN 2444/sshd
    tcp6 0 0 localhost:953 *:* LISTEN 3469/named
    tcp6 0 0 *:smtp *:* LISTEN 1651/master
    tcp6 0 0 *:https *:* LISTEN 3213/apache2
    tcp6 0 0 server.xxx.org:ssh ::ffff:192.168.1.:35839 ESTABLISHED2526/sshd: administ





    Thanks in advance.. ;)
     
  13. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

  14. ParDust

    ParDust New Member

    Thanks!. Problem is dynamic ip address which was blacklisted, i created a reverse zone file now gmail accepts my emails however unlikely yahoo does not.

    Today i will try to connect mail server outside local network with a mail client to see if pop3-smtp configuration is ok.
     
  15. solutions_linux

    solutions_linux New Member

    Sendmail is legacy MTA of Unix(Its location is hardcoded in many previous apps). So, while postfix installation, we need to first forcibly uninstall sendmail Then postfix installs its own binary named sendmail in /usr/bin/sendmail.
    So, I mean to say that sendmail binary exists in both. Your app will work in either cases.
     
  16. gamera

    gamera New Member

    Im getting a very similar issue with my server.

    When sending to a email account on the server it all works fine. To any external domain it does not.. First noticed the issue as I was not getting monitoring emails to externally hosted email box.

    Now php forms and user accounts on site are unable to send validation emails, passwords etc to member accounts.

    IP is static and ISP do not filter smtp connections and I am sure of this as I work for them :p

    ISPC 2 latest install/version
    Centos 5.2 - Perfect Server Installation

    Now I am a noob to email server stuff so you will not only have to tell me what I can give you to further assist but also where I can find it.

    I originally suspected global php settings to be the issue but not after reading others comments, now suspect postfix or ....

    ...to be the issue.

    Any help is very much appreciated.
     
  17. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

  18. gamera

    gamera New Member

    Not black listed.

    Tried to paste log into reply and keep getting error:

    The message you have entered is too short. Please lengthen your message to at least 10 characters.

    WTF its a hell of alot more than ten.
     
  19. gamera

    gamera New Member

    Fixed by port issue on lns.
     

Share This Page