How does PHP's `mail` work?

前端 未结 4 1871
你的背包
你的背包 2020-12-09 07:18

PHP\'s mail function seems to deliver mail on a clean system, with no apparent configuration done by the administrator or webmaster (no SMTP configuration in

4条回答
  •  粉色の甜心
    2020-12-09 08:12

    You can detect how it works as below.

    First method

    $ ltrace php -r "mail('tester@127.0.0.1', 'Test', 'Hello world');" 2>&1 | grep sendmail
    memcpy(0x095ea168, "sendmail_from", 14)          = 0x095ea168
    memcpy(0x095ea1e0, "sendmail_path", 14)          = 0x095ea1e0
    popen("/usr/sbin/sendmail -t -i ", "w")          = 0x0977c7c0
    

    From the results of the above command can be seen that the popen() function opens the process of /usr/sbin/sendmail -t -i.

    $ ls -l /usr/sbin/sendmail
    ... /usr/sbin/sendmail -> exim4
    

    So sendmail is the symbolic link to exim4 and hence sendmail -t -i invokes exim4 -t -i.

    And in the manual page of exim4 you can read about these options -t -i:

    $ man exim4 | grep ' -t -i'
    -ti       This option is exactly equivalent to -t -i. It is provided for compatibility with Sendmail.
    

    Second method

    Install snoopy and run:

    # grep snoopy /var/log/auth.log | tail
    ... php -r mail('tester@127.0.0.1', 'Test', 'Hello world');
    ... /usr/sbin/sendmail -t -i
    ... /usr/sbin/exim4 -Mc 1YxxYn-0006a7-Nw
    ... /usr/sbin/exim4 -t -oem -oi -f <> -E1YxxYn-0006a7-Nw
    ... /usr/sbin/exim4 -Mc 1YxxYn-0006aB-Oj
    

    The results of the above command show the sequence of the commands which were performed.

提交回复
热议问题