开发者

Is it possible to retrieve emails sent by php mail() on the server?

I am using PHP's mail() function to send emails from my application. Is there any way to see the emails that have been sent if I SSH into the server? I need the actual body of the emails not just a record of the action. This is probably a longshot but any help would be appreciated.

EDIT: I should have been clearer. This is for messages already sent in the past. I can definitely take steps to log or otherwise report sent messages in the future but is there a way t开发者_开发问答o retrieve messages that have already been sent?


The mail function doesn't append mails to a Sent mailbox in the server, so I'd say no: as it is you can't find the body of emails sent through PHP.

However you might create your own mail function to log somewhere the content you're sending.

Also there are 2 lines of config in php.ini which makes me think that you could append it to an existing mailbox with the right config.

;sendmail_path =
; 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 =


I usually add an argument to my mail function to indicate that I want to write a record of the email along with the content into an HTML file. That way, when I am testing, I can browse to a temp folder and see what the email would have looked like. Here's some mock code:

function send_email($to=false,$message=false,$from=false,$test=false) {

    ... do stuff to send email ...

    if ($test == true) {
        $out = 'Mail to: '.$to.'<br />From: '.$from.'<br />Time: '.date('m/d/Y h:i', time()).'<hr />'.$message; 

        // use a random string for a file name
        $fname = random_string(20); 

        .. write the $out var to a file named $fname ...
    }

}


If you have access to the email address that this is being sent to, then you can use PHPs IMAP functions. http://www.php.net/manual/en/book.imap.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜