Switch away from the IMAP functions, suggest using an IMAP library instead, and update the example to do that
This commit is contained in:
parent
57ef8c914f
commit
381c209df1
|
|
@ -56,7 +56,8 @@
|
||||||
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
|
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
|
||||||
"psr/log": "For optional PSR-3 debug logging",
|
"psr/log": "For optional PSR-3 debug logging",
|
||||||
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)",
|
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)",
|
||||||
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication"
|
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication",
|
||||||
|
"directorytree/imapengine": "For uploading sent messages via IMAP, see gmail example"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
|
|
|
||||||
|
|
@ -83,26 +83,26 @@ if (!$mail->send()) {
|
||||||
echo 'Message sent!';
|
echo 'Message sent!';
|
||||||
//Section 2: IMAP
|
//Section 2: IMAP
|
||||||
//Uncomment these to save your message in the 'Sent Mail' folder.
|
//Uncomment these to save your message in the 'Sent Mail' folder.
|
||||||
#if (save_mail($mail)) {
|
#if (save_mail($mail->getSentMIMEMessage())) {
|
||||||
# echo "Message saved!";
|
# echo "Message saved!";
|
||||||
#}
|
#}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Section 2: IMAP
|
//Section 2: IMAP
|
||||||
//IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
|
//This example uses the directorytree/imapengine IMAP library: https://imapengine.com
|
||||||
//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
|
//Earlier versions of this code used the deprecated PHP imap_* functions.
|
||||||
//You can use imap_getmailboxes($imapStream, '/imap/ssl', '*' ) to get a list of available folders or labels, this can
|
function save_mail($message) {
|
||||||
//be useful if you are trying to get this working on a non-Gmail IMAP server.
|
$mailbox = new \DirectoryTree\ImapEngine\Mailbox([
|
||||||
function save_mail($mail)
|
'host' => 'imap.gmail.com',
|
||||||
{
|
'port' => 993,
|
||||||
//You can change 'Sent Mail' to any other folder or tag
|
'encryption' => 'ssl',
|
||||||
$path = '{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail';
|
'username' => 'user@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
]);
|
||||||
|
|
||||||
//Tell your server to open an IMAP connection using the same username and password as you used for SMTP
|
// Find the "sent" messages folder – yours may have a different name.
|
||||||
$imapStream = imap_open($path, $mail->Username, $mail->Password);
|
$folder = $mailbox->folders()->find('Sent Mail');
|
||||||
|
|
||||||
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
|
$folder->messages()->append($message);
|
||||||
imap_close($imapStream);
|
return true;
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue