Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP mail function

Options
  • 09-01-2004 5:26pm
    #1
    Subscribers Posts: 1,911 ✭✭✭


    I have this piece of php code which is supposed to e-mail me:

    [PHP]
    $mail_address = 'karl@eeng.may.ie\r\n';
    $subject = 'test from php\r\n';
    $message = 'This is a test message\r\n';
    $from = "From: root@{$_SERVER}\r\n";
    $reply = "Reply-To: root@{$_SERVER}\r\n";
    $header = 'X-Mailer: PHP/".phpversion()."\r\n';
    echo 'Trying to mail using: <br>';
    echo $mail_address.'<br>'.$subject.'<br>'.$message.'<br>'.$from.'<br>';

    if (mail($mail_address, $subject, $message, $from.$reply.$header)){
    echo 'sucess';
    } else {
    echo 'fail';
    }
    [/PHP]

    It doesn't.

    All that appears in my mail logs is:
    @400000003ffed5a621634784 new msg 64400
    @400000003ffed5a621635ef4 info msg 64400: bytes 329 from <root@hal.eeng.may.ie> qp 29684 uid 48
    @400000003ffed5a621a0d554 end msg 64400

    Now I'm using qmail rather than sendmail on the machine. So is it a problem with qmail or have done something wrong in the above code? It's PHP version 4.3.1


Comments

  • Registered Users Posts: 1,023 ✭✭✭[CrimsonGhost]


    I've never included the \r\n in the first 3 arguments passed to the mail function. So try without them and without additional header arguments initially.


  • Subscribers Posts: 1,911 ✭✭✭Draco


    Nope. Same result. They ended up there is a fit of desperation.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    I'd remove the \r\n anyway, especially from the Email addy and subject line.

    Does the mail deliver and is unreadable, or does it not deliver?
    If it doesn't deliver I would say check your server settings (in php.ini file in windows afaik, not sure where in UNIX/Linux).

    I would say leave out the fourth argument in the mail() function with the headers. Maybe try adding them to the message?


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by Draco
    Now I'm using qmail rather than sendmail on the machine.
    Is sendmail_path (check using phpinfo) is going to to the correct exec?


  • Registered Users Posts: 927 ✭✭✭decob


    as The Corinthian said, check the path of sendmail_path. Qmail should have a sendmail wrapper that it should be pointed to in you php.ini file,
    from http://ie2.php.net/mail
    sendmail_path string

    Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail. configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

    Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, Qmail users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject.


  • Advertisement
  • Subscribers Posts: 1,911 ✭✭✭Draco


    From phpinfo():
    sendmail_path /var/qmail/bin/sendmail
    Have tried it with out the /r/n or the last 2 variables. It seems to hit the mail server and then die for some reason. I was thinking that the message was malformed in some manner.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by Draco
    It seems to hit the mail server and then die for some reason. I was thinking that the message was malformed in some manner.
    The problem may not be php related then. Is port 25 (for SMTP) blocked on the server (e.g. firewalled)? Or is it being used by another service?


  • Subscribers Posts: 1,911 ✭✭✭Draco


    Nope. If I use the unix mail function it all works swimingly.


  • Subscribers Posts: 1,911 ✭✭✭Draco


    Yup, it's definitely something up with qmail. Tested it on a machine with a proper sendmail instal and it works perfectly.

    Thanks for the help.


Advertisement