From ccdeae108a28fec89fab2ab8d4ccf7ec27d93479 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 2 Aug 2017 16:20:32 +0200 Subject: [PATCH] IMAP section in the Gmail example (#1117) Add IMAP example into gmail example --- examples/gmail.phps | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/gmail.phps b/examples/gmail.phps index b3cc02d5..121ca70a 100644 --- a/examples/gmail.phps +++ b/examples/gmail.phps @@ -1,6 +1,7 @@ send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; + //Section 2: IMAP + //Uncomment these to save your message in the 'Sent Mail' folder. + #if (save_mail($mail)) { + # echo "Message saved!"; + #} +} + +//Section 2: IMAP +//IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php +//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php +//You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can +//be useful if you are trying to get this working on a non-Gmail IMAP server. +function save_mail($mail) { + //You can change 'Sent Mail' to any other folder or tag + $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail"; + + //Tell your server to open an IMAP connection using the same username and password as you used for SMTP + $imapStream = imap_open($path, $mail->Username, $mail->Password); + + $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage()); + imap_close($imapStream); + + return $result; }