diff --git a/composer.json b/composer.json index 05b05c75..63d0ffd6 100644 --- a/composer.json +++ b/composer.json @@ -42,8 +42,8 @@ "doctrine/annotations": "^1.2.6 || ^1.13.3", "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", - "phpcompatibility/php-compatibility": "^9.3.5", - "squizlabs/php_codesniffer": "^3.7.2", + "phpcompatibility/php-compatibility": "^10.0.0@dev", + "squizlabs/php_codesniffer": "^3.13.5", "yoast/phpunit-polyfills": "^1.0.4" }, "suggest": { @@ -56,8 +56,11 @@ "league/oauth2-google": "Needed for Google XOAUTH2 authentication", "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)", - "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", + "prefer-stable": true, "autoload": { "psr-4": { "PHPMailer\\PHPMailer\\": "src/" diff --git a/examples/gmail.phps b/examples/gmail.phps index fe6e09a9..35e49966 100644 --- a/examples/gmail.phps +++ b/examples/gmail.phps @@ -83,26 +83,24 @@ if (!$mail->send()) { echo 'Message sent!'; //Section 2: IMAP //Uncomment these to save your message in the 'Sent Mail' folder. - #if (save_mail($mail)) { - # echo "Message saved!"; - #} + #save_mail($mail->getSentMIMEMessage()); } //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) +//This example uses the directorytree/imapengine IMAP library: https://imapengine.com +//Earlier versions of this code used the deprecated PHP imap_* functions. +function save_mail($message) { - //You can change 'Sent Mail' to any other folder or tag - $path = '{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail'; + $mailbox = new \DirectoryTree\ImapEngine\Mailbox([ + 'host' => 'imap.gmail.com', + 'port' => 993, + 'encryption' => 'ssl', + '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 - $imapStream = imap_open($path, $mail->Username, $mail->Password); + // Find the "sent" messages folder – yours may have a different name. + $folder = $mailbox->folders()->find('Sent Mail'); - $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage()); - imap_close($imapStream); - - return $result; + $folder->messages()->append($message); } diff --git a/examples/mailing_list.phps b/examples/mailing_list.phps index 4a536e7c..9eb05d63 100644 --- a/examples/mailing_list.phps +++ b/examples/mailing_list.phps @@ -8,7 +8,7 @@ use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; -error_reporting(E_STRICT | E_ALL); +error_reporting(E_ALL); date_default_timezone_set('Etc/UTC'); @@ -51,7 +51,10 @@ foreach ($result as $row) { try { $mail->addAddress($row['email'], $row['full_name']); } catch (Exception $e) { - echo 'Invalid address skipped: ' . htmlspecialchars($row['email']) . '
'; + printf( + 'Invalid address skipped: %s
', + htmlspecialchars($row['email'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401) + ); continue; } if (!empty($row['photo'])) { @@ -66,8 +69,11 @@ foreach ($result as $row) { try { $mail->send(); - echo 'Message sent to :' . htmlspecialchars($row['full_name']) . ' (' . - htmlspecialchars($row['email']) . ')
'; + printf( + 'Message sent to : %s (%s)
', + htmlspecialchars($row['full_name'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401), + htmlspecialchars($row['email'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401) + ); //Mark it as sent in the DB mysqli_query( $mysql, @@ -75,7 +81,11 @@ foreach ($result as $row) { mysqli_real_escape_string($mysql, $row['email']) . "'" ); } catch (Exception $e) { - echo 'Mailer Error (' . htmlspecialchars($row['email']) . ') ' . $mail->ErrorInfo . '
'; + printf( + 'Mailer Error (%s) %s
', + htmlspecialchars($row['email'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401), + $mail->ErrorInfo + ); //Reset the connection to abort sending this message //The loop will continue trying to send to the rest of the list $mail->getSMTPInstance()->reset(); diff --git a/examples/send_file_upload.phps b/examples/send_file_upload.phps index 31d22837..8c6ec070 100644 --- a/examples/send_file_upload.phps +++ b/examples/send_file_upload.phps @@ -54,7 +54,7 @@ if (array_key_exists('userfile', $_FILES)) { diff --git a/examples/send_multiple_file_upload.phps b/examples/send_multiple_file_upload.phps index aeb65c14..e892ecb5 100644 --- a/examples/send_multiple_file_upload.phps +++ b/examples/send_multiple_file_upload.phps @@ -54,7 +54,7 @@ if (array_key_exists('userfile', $_FILES)) { diff --git a/get_oauth_token.php b/get_oauth_token.php index 0e54a00b..9342b9c7 100644 --- a/get_oauth_token.php +++ b/get_oauth_token.php @@ -178,5 +178,5 @@ if (!isset($_GET['code'])) { ); //Use this to interact with an API on the users behalf //Use this to get a new access token if the old one expires - echo 'Refresh Token: ', htmlspecialchars($token->getRefreshToken()); + echo 'Refresh Token: ', htmlspecialchars($token->getRefreshToken(), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e2d1e5c6..bf51a72c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -27,14 +27,7 @@ - - - - - - - - +