Search code examples
phpsmtpphpmailer

How to get the message body from PHPMailer?


I use PHPMailer to send email via SMTP. It works, but it doesn't save the sent emails in

sent items. I want to make to sent emails in the sent items, any idea?

I know can use imap_append function to achieve it. But, how to do that?

The PHPMailer seems doesn't has the function to return the $message.

if ($return = $mail->Send()) {

$stream = imap_open("{{$host}:993/imap/ssl}Sent Items", $user_name, $user_pwd); 

imap_append($stream, "{{$host}:993/imap/ssl}Sent Items" , $message  , "\\Seen");

imap_close($stream);

};

How to get the message body from PHPMailer?


Solution

  • The instance variables from PHPMailer are all public. Looking at the source you can just use:

    $mail->Body
    

    If you want the plain body including the all boundaries you could also use:

    $mail->CreateBody();
    

    See: http://phpmailer.svn.sourceforge.net/viewvc/phpmailer/trunk/phpmailer/class.phpmailer.php?revision=452&view=markup