Ajout de PHPMailer pour envoyer des mails de confirmation de réservation
This commit is contained in:
parent
7cacf9f3ff
commit
01ea3fce4e
32
css/ReservationSuccess.css
Normal file
32
css/ReservationSuccess.css
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
.content {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 20px auto;
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #fff;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.reservation-successful-section {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reservation-successful-section h1 {
|
||||||
|
color: #00a651;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reservation-successful-section p {
|
||||||
|
font-size: 18px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-button {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 30px;
|
||||||
|
padding: 10px 20px;
|
||||||
|
background-color: #FFB039;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
@ -42,7 +42,7 @@
|
|||||||
<p>Choisissez une date et une heure parmi les disponibilités ci-dessous pour réserver une table.</p>
|
<p>Choisissez une date et une heure parmi les disponibilités ci-dessous pour réserver une table.</p>
|
||||||
|
|
||||||
<!-- Formulaire de réservation avec sélecteur de plage horaire -->
|
<!-- Formulaire de réservation avec sélecteur de plage horaire -->
|
||||||
<form action="https://dwarves.iut-fbleau.fr/requete.php" method="post" class="reservation-form" onsubmit="showReservationConfirmation()">
|
<form action="../php/send_confirmation_email.php" method="post" class="reservation-form" onsubmit="showReservationConfirmation()">
|
||||||
<label for="name">Nom :</label>
|
<label for="name">Nom :</label>
|
||||||
<input type="text" id="name" name="name" required>
|
<input type="text" id="name" name="name" required>
|
||||||
|
|
||||||
@ -65,7 +65,6 @@
|
|||||||
<option value="19:00">19:00</option>
|
<option value="19:00">19:00</option>
|
||||||
<option value="20:00">20:00</option>
|
<option value="20:00">20:00</option>
|
||||||
<option value="18:00">21:00</option>
|
<option value="18:00">21:00</option>
|
||||||
<!-- Ajoutez d'autres options selon vos disponibilités -->
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="guests">Nombre de convives :</label>
|
<label for="guests">Nombre de convives :</label>
|
||||||
@ -74,9 +73,6 @@
|
|||||||
<button type="submit">Réserver</button>
|
<button type="submit">Réserver</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div id="confirmation-message" style="display: none;">
|
|
||||||
Merci pour votre réservation ! Votre table a bien été réservée.
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -133,7 +129,6 @@
|
|||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="../js/script.js"></script>
|
<script src="../js/script.js"></script>
|
||||||
<script src="../js/reservation.js"></script>
|
|
||||||
<button id="scrollTopBtn" onclick="scrollToTop()">
|
<button id="scrollTopBtn" onclick="scrollToTop()">
|
||||||
<span>🚀</span>
|
<span>🚀</span>
|
||||||
</button>
|
</button>
|
||||||
|
103
html/reservationSucces.html
Normal file
103
html/reservationSucces.html
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr-FR">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="../css/styles.css">
|
||||||
|
<link rel="stylesheet" href="../css/ReservationSuccess.css">
|
||||||
|
<title>Réservation réussie - Neo Eat</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header class="navbar">
|
||||||
|
<div class="logo">
|
||||||
|
<img src="../img/Logo/LogoNeoEat.png" alt="Neo Eat Logo">
|
||||||
|
</div>
|
||||||
|
<nav class="nav-links">
|
||||||
|
<a href="index.html">Accueil</a>
|
||||||
|
<a href="#">Menu</a>
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#" class="dropdown-btn">À propos <i class="ri-arrow-down-s-line"></i></a>
|
||||||
|
<div class="dropdown-content">
|
||||||
|
<a href="faq.html">FAQ</a>
|
||||||
|
<a href="#">Nos chefs</a>
|
||||||
|
<a href="#">Nos fournisseurs</a>
|
||||||
|
<a href="#">Notre équipe</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a href="../html/contact.html" class="nav-link">Contact</a>
|
||||||
|
<a href="../html/reservation.html" class="nav-link reserve-btn">Réserver une table</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- BARRE DU MENU BURGER -->
|
||||||
|
<div class="burger-menu">
|
||||||
|
<div class="bar"></div>
|
||||||
|
<div class="bar"></div>
|
||||||
|
<div class="bar"></div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<section class="reservation-successful-section">
|
||||||
|
<h1>Réservation réussie</h1>
|
||||||
|
<p>Merci pour votre réservation ! Votre table a bien été réservée et un mail de confirmation vous as été envoyé.</p>
|
||||||
|
<a href="index.html" class="home-button">Retourner à l'accueil</a>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer">
|
||||||
|
<div class="footer-content">
|
||||||
|
<div class="footer-section">
|
||||||
|
<h3>Plan du site</h3>
|
||||||
|
<!-- Ajoutez ici les liens vers les différentes sections du site -->
|
||||||
|
</div>
|
||||||
|
<div class="footer-section">
|
||||||
|
<h3>Mentions légales</h3>
|
||||||
|
<!-- Ajoutez ici les informations légales nécessaires -->
|
||||||
|
</div>
|
||||||
|
<div class="footer-section">
|
||||||
|
<h3>Contact</h3>
|
||||||
|
<p>Email : <a href="mailto:neoeat.sav@gmail.com">neoeat.sav@gmail.com</a></p>
|
||||||
|
<p>Téléphone : <a href="tel:+33175489632">+33 01 75 48 96 32</a></p>
|
||||||
|
</div>
|
||||||
|
<div class="footer-section horizontally-aligned">
|
||||||
|
<h3>Réseaux sociaux</h3>
|
||||||
|
<div class="logo-reseaux">
|
||||||
|
<p>
|
||||||
|
<a href="https://www.instagram.com/neoeat75/" target="_blank" class="social-icon">
|
||||||
|
<img src="../img/RéseauxSociaux/Instagram.png" alt="Instagram">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://www.facebook.com/neoeat75/" target="_blank" class="social-icon">
|
||||||
|
<img src="../img/RéseauxSociaux/Facebook.png" alt="Facebook">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://www.X.com/neoeat75/" target="_blank" class="social-icon">
|
||||||
|
<img src="../img/RéseauxSociaux/X.png" alt="X">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://www.youtube.com/channel/UCNSi53sTJ7LYqgonJ4CfCCQ" target="_blank" class="social-icon">
|
||||||
|
<img src="../img/RéseauxSociaux/Youtube.png" alt="Youtube">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://www.TripAdvisor.com/neoeat/" target="_blank" class="social-icon">
|
||||||
|
<img src="../img/RéseauxSociaux/Tripadvisor.png" alt="TripAdvisor">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="footer-signature">
|
||||||
|
<img src="../img/Logo/LogoNeoEat.png" alt="Neo Eat Logo">
|
||||||
|
<p>© 2024 Neo Eat. Tous droits réservés.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<button id="scrollTopBtn" onclick="scrollToTop()">
|
||||||
|
<span>🚀</span>
|
||||||
|
</button>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -3,10 +3,3 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split('T')[0];
|
||||||
document.getElementById('date').min = today;
|
document.getElementById('date').min = today;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Pour afficher un message de confirmation que la table à bien été réserver
|
|
||||||
function showReservationConfirmation() {
|
|
||||||
var confirmationMessage = document.getElementById("confirmation-message");
|
|
||||||
confirmationMessage.style.display = "block";
|
|
||||||
}
|
|
21
php/PHP/fichier/php/PHP/PHPMailer/.codecov.yml
Normal file
21
php/PHP/fichier/php/PHP/PHPMailer/.codecov.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
codecov:
|
||||||
|
notify:
|
||||||
|
after_n_builds: 2
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
round: nearest
|
||||||
|
# Status will be green when coverage is between 70 and 100%.
|
||||||
|
range: "70...100"
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
threshold: 2%
|
||||||
|
paths:
|
||||||
|
- "src"
|
||||||
|
patch:
|
||||||
|
default:
|
||||||
|
threshold: 0%
|
||||||
|
paths:
|
||||||
|
- "src"
|
||||||
|
|
||||||
|
comment: false
|
15
php/PHP/fichier/php/PHP/PHPMailer/.editorconfig
Normal file
15
php/PHP/fichier/php/PHP/PHPMailer/.editorconfig
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
16
php/PHP/fichier/php/PHP/PHPMailer/.gitattributes
vendored
Normal file
16
php/PHP/fichier/php/PHP/PHPMailer/.gitattributes
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
* text=auto
|
||||||
|
|
||||||
|
/.codecov.yml export-ignore
|
||||||
|
/.gitattributes export-ignore
|
||||||
|
/.github export-ignore
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/.phan export-ignore
|
||||||
|
/.scrutinizer.yml export-ignore
|
||||||
|
/changelog.md export-ignore
|
||||||
|
/docs export-ignore
|
||||||
|
/examples export-ignore
|
||||||
|
/phpcs.xml.dist export-ignore
|
||||||
|
/phpdoc.dist.xml export-ignore
|
||||||
|
/phpunit.xml.dist export-ignore
|
||||||
|
/test export-ignore
|
||||||
|
/UPGRADING.md export-ignore
|
6
php/PHP/fichier/php/PHP/PHPMailer/.github/FUNDING.yml
vendored
Normal file
6
php/PHP/fichier/php/PHP/PHPMailer/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: Synchro
|
||||||
|
patreon: marcusbointon
|
||||||
|
tidelift: "packagist/phpmailer/phpmailer"
|
||||||
|
custom: https://marcus.bointon.com/donations/
|
23
php/PHP/fichier/php/PHP/PHPMailer/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
23
php/PHP/fichier/php/PHP/PHPMailer/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: If you've found a bug in PHPMailer, this is the right place to report it
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Please check these things before submitting your issue:
|
||||||
|
|
||||||
|
- [ ] *Read the error message* you're seeing - it often tells you what is wrong, and may contain useful links & instructions
|
||||||
|
- [ ] Make sure you're using the latest version of PHPMailer
|
||||||
|
- [ ] Check that your problem is not dealt with in [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting), especially if you're having problems connecting to Gmail or GoDaddy
|
||||||
|
- [ ] Include sufficient code to reproduce your problem
|
||||||
|
- [ ] If you're having an SMTP issue, include the debug output generated with `SMTPDebug = 2` set
|
||||||
|
- [ ] If you have a question about how to use PHPMailer (rather than reporting a bug in it), tag a question on Stack Overflow with `phpmailer`, but [**search first**](https://stackoverflow.com/questions/tagged/phpmailer)!
|
||||||
|
|
||||||
|
# Problem description
|
||||||
|
|
||||||
|
# Code to reproduce
|
||||||
|
|
||||||
|
# Debug output
|
15
php/PHP/fichier/php/PHP/PHPMailer/.github/actions/build-docs/Dockerfile
vendored
Normal file
15
php/PHP/fichier/php/PHP/PHPMailer/.github/actions/build-docs/Dockerfile
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
FROM phpdoc/phpdoc
|
||||||
|
|
||||||
|
LABEL "repository"="https://github.com/PHPMailer/PHPMailer"
|
||||||
|
|
||||||
|
LABEL "com.github.actions.name"="Build Docs"
|
||||||
|
LABEL "com.github.actions.description"="Build Docs with phpDocumentor"
|
||||||
|
LABEL "com.github.actions.icon"="file-text"
|
||||||
|
LABEL "com.github.actions.color"="blue"
|
||||||
|
|
||||||
|
# don't show errors
|
||||||
|
RUN echo "display_errors = Off" > $PHP_INI_DIR/conf.d/errors.ini
|
||||||
|
|
||||||
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
5
php/PHP/fichier/php/PHP/PHPMailer/.github/actions/build-docs/entrypoint.sh
vendored
Executable file
5
php/PHP/fichier/php/PHP/PHPMailer/.github/actions/build-docs/entrypoint.sh
vendored
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
/opt/phpdoc/bin/phpdoc
|
14
php/PHP/fichier/php/PHP/PHPMailer/.github/dependabot.yml
vendored
Normal file
14
php/PHP/fichier/php/PHP/PHPMailer/.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Dependabot configuration.
|
||||||
|
#
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
open-pull-requests-limit: 5
|
||||||
|
commit-message:
|
||||||
|
prefix: "GH Actions:"
|
29
php/PHP/fichier/php/PHP/PHPMailer/.github/workflows/docs.yaml
vendored
Normal file
29
php/PHP/fichier/php/PHP/PHPMailer/.github/workflows/docs.yaml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: Docs
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
permissions: {}
|
||||||
|
jobs:
|
||||||
|
build_and_publish:
|
||||||
|
permissions:
|
||||||
|
contents: write # to push changes in repo (jamesives/github-pages-deploy-action)
|
||||||
|
|
||||||
|
name: Build and publish Docs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.repository == 'PHPMailer/PHPMailer'
|
||||||
|
steps:
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
- name: Build Docs
|
||||||
|
uses: ./.github/actions/build-docs
|
||||||
|
- name: Publish Docs to gh-pages
|
||||||
|
uses: JamesIves/github-pages-deploy-action@v4
|
||||||
|
with:
|
||||||
|
branch: gh-pages
|
||||||
|
folder: docs
|
||||||
|
env:
|
||||||
|
BUILD_DIR: docs/
|
||||||
|
GH_PAT: ${{ secrets.GH_PAT }}
|
62
php/PHP/fichier/php/PHP/PHPMailer/.github/workflows/scorecards.yml
vendored
Normal file
62
php/PHP/fichier/php/PHP/PHPMailer/.github/workflows/scorecards.yml
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
name: Scorecards supply-chain security
|
||||||
|
on:
|
||||||
|
# Only the default branch is supported.
|
||||||
|
branch_protection_rule:
|
||||||
|
schedule:
|
||||||
|
- cron: '39 20 * * 1'
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
# Declare default permissions as read only.
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analysis:
|
||||||
|
name: Scorecards analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
# Needed to upload the results to code-scanning dashboard.
|
||||||
|
security-events: write
|
||||||
|
# Used to receive a badge. (Upcoming feature)
|
||||||
|
id-token: write
|
||||||
|
# Needs for private repositories.
|
||||||
|
contents: read
|
||||||
|
actions: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout code"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: "Run analysis"
|
||||||
|
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736
|
||||||
|
with:
|
||||||
|
results_file: results.sarif
|
||||||
|
results_format: sarif
|
||||||
|
# (Optional) Read-only PAT token. Uncomment the `repo_token` line below if:
|
||||||
|
# - you want to enable the Branch-Protection check on a *public* repository, or
|
||||||
|
# - you are installing Scorecards on a *private* repository
|
||||||
|
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
|
||||||
|
# repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
|
||||||
|
|
||||||
|
# Publish the results for public repositories to enable scorecard badges. For more details, see
|
||||||
|
# https://github.com/ossf/scorecard-action#publishing-results.
|
||||||
|
# For private repositories, `publish_results` will automatically be set to `false`, regardless
|
||||||
|
# of the value entered here.
|
||||||
|
publish_results: true
|
||||||
|
|
||||||
|
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||||
|
# format to the repository Actions tab.
|
||||||
|
- name: "Upload artifact"
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: SARIF file
|
||||||
|
path: results.sarif
|
||||||
|
retention-days: 5
|
||||||
|
|
||||||
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
|
- name: "Upload to code-scanning"
|
||||||
|
uses: github/codeql-action/upload-sarif@v3
|
||||||
|
with:
|
||||||
|
sarif_file: results.sarif
|
178
php/PHP/fichier/php/PHP/PHPMailer/.github/workflows/tests.yml
vendored
Normal file
178
php/PHP/fichier/php/PHP/PHPMailer/.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
name: "Tests"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
# Allow manually triggering the workflow.
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read # to fetch code (actions/checkout)
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
coding-standard:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
name: Coding standards
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: 'latest'
|
||||||
|
coverage: none
|
||||||
|
tools: cs2pr
|
||||||
|
|
||||||
|
# Install dependencies and handle caching in one go.
|
||||||
|
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
|
||||||
|
- name: Install Composer dependencies
|
||||||
|
uses: "ramsey/composer-install@v2"
|
||||||
|
with:
|
||||||
|
# Bust the cache at least once a month - output format: YYYY-MM.
|
||||||
|
custom-cache-suffix: $(date -u "+%Y-%m")
|
||||||
|
|
||||||
|
- name: Check coding standards
|
||||||
|
id: phpcs
|
||||||
|
run: ./vendor/bin/phpcs -s --report-full --report-checkstyle=./phpcs-report.xml
|
||||||
|
|
||||||
|
- name: Show PHPCS results in PR
|
||||||
|
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
|
||||||
|
run: cs2pr ./phpcs-report.xml
|
||||||
|
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php: ['5.5', '7.2', '8.0', '8.1', '8.2', '8.3']
|
||||||
|
experimental: [false]
|
||||||
|
include:
|
||||||
|
- php: '8.4'
|
||||||
|
experimental: true
|
||||||
|
|
||||||
|
name: "Lint: PHP ${{ matrix.php }}"
|
||||||
|
continue-on-error: ${{ matrix.experimental }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
coverage: none
|
||||||
|
tools: cs2pr
|
||||||
|
|
||||||
|
# Install dependencies and handle caching in one go.
|
||||||
|
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
|
||||||
|
- name: Install Composer dependencies
|
||||||
|
uses: "ramsey/composer-install@v2"
|
||||||
|
with:
|
||||||
|
# Bust the cache at least once a month - output format: YYYY-MM.
|
||||||
|
custom-cache-suffix: $(date -u "+%Y-%m")
|
||||||
|
|
||||||
|
- name: Lint against parse errors
|
||||||
|
if: ${{ matrix.php != '8.4' }}
|
||||||
|
run: composer lint -- --checkstyle | cs2pr
|
||||||
|
|
||||||
|
- name: Lint against future parse errors (PHP 8.4)
|
||||||
|
if: ${{ matrix.php == '8.4' }}
|
||||||
|
run: composer lint
|
||||||
|
|
||||||
|
test:
|
||||||
|
needs: ['coding-standard', 'lint']
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
|
||||||
|
coverage: [false]
|
||||||
|
experimental: [false]
|
||||||
|
include:
|
||||||
|
# Run code coverage on high/low PHP.
|
||||||
|
- php: '5.5'
|
||||||
|
coverage: true
|
||||||
|
experimental: false
|
||||||
|
- php: '8.3'
|
||||||
|
coverage: true
|
||||||
|
experimental: false
|
||||||
|
|
||||||
|
# Experimental builds. These are allowed to fail.
|
||||||
|
- php: '8.4'
|
||||||
|
coverage: false
|
||||||
|
experimental: true
|
||||||
|
|
||||||
|
name: "Test: PHP ${{ matrix.php }}"
|
||||||
|
|
||||||
|
continue-on-error: ${{ matrix.experimental }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
|
||||||
|
ini-values: sendmail_path=/usr/sbin/sendmail -t -i, error_reporting=E_ALL, display_errors=On
|
||||||
|
extensions: imap, mbstring, intl, ctype, filter, hash
|
||||||
|
|
||||||
|
# Install dependencies and handle caching in one go.
|
||||||
|
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
|
||||||
|
- name: Install PHP packages - normal
|
||||||
|
if: ${{ matrix.php != '8.4' }}
|
||||||
|
uses: "ramsey/composer-install@v2"
|
||||||
|
with:
|
||||||
|
# Bust the cache at least once a month - output format: YYYY-MM.
|
||||||
|
custom-cache-suffix: $(date -u "+%Y-%m")
|
||||||
|
|
||||||
|
- name: Install PHP packages - ignore-platform-reqs
|
||||||
|
if: ${{ matrix.php == '8.4' }}
|
||||||
|
uses: "ramsey/composer-install@v2"
|
||||||
|
with:
|
||||||
|
composer-options: --ignore-platform-reqs
|
||||||
|
# Bust the cache at least once a month - output format: YYYY-MM.
|
||||||
|
custom-cache-suffix: $(date -u "+%Y-%m")
|
||||||
|
|
||||||
|
# Install postfix and automatically retry if the install failed, which happens reguarly.
|
||||||
|
# @link https://github.com/marketplace/actions/retry-step
|
||||||
|
- name: Install postfix
|
||||||
|
uses: nick-invision/retry@v2
|
||||||
|
with:
|
||||||
|
timeout_minutes: 2
|
||||||
|
max_attempts: 3
|
||||||
|
retry_wait_seconds: 8
|
||||||
|
command: |
|
||||||
|
sudo apt-get install -y libsqlite3-0 postfix
|
||||||
|
sudo systemctl stop postfix.service
|
||||||
|
|
||||||
|
- name: Set up sendmail
|
||||||
|
run: |
|
||||||
|
smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
|
||||||
|
mkdir -p build/logs
|
||||||
|
sudo cp test/testbootstrap-dist.php test/testbootstrap.php
|
||||||
|
sudo chmod +x test/fakesendmail.sh
|
||||||
|
sudo mkdir -p /var/qmail/bin
|
||||||
|
sudo cp test/fakesendmail.sh /var/qmail/bin/sendmail
|
||||||
|
sudo cp test/fakesendmail.sh /usr/sbin/sendmail
|
||||||
|
|
||||||
|
- name: Run tests, no code coverage
|
||||||
|
if: ${{ matrix.coverage == false }}
|
||||||
|
run: ./vendor/bin/phpunit --no-coverage
|
||||||
|
|
||||||
|
- name: Run tests with code coverage
|
||||||
|
if: ${{ matrix.coverage == true }}
|
||||||
|
run: vendor/bin/phpunit
|
||||||
|
|
||||||
|
- name: Send coverage report to Codecov
|
||||||
|
if: ${{ success() && matrix.coverage == true }}
|
||||||
|
uses: codecov/codecov-action@v3
|
||||||
|
with:
|
||||||
|
files: ./build/logs/clover.xml
|
||||||
|
fail_ci_if_error: true
|
||||||
|
verbose: true
|
||||||
|
# see https://github.com/codecov/codecov-action/issues/557
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
16
php/PHP/fichier/php/PHP/PHPMailer/.gitignore
vendored
Normal file
16
php/PHP/fichier/php/PHP/PHPMailer/.gitignore
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
docs/*
|
||||||
|
!docs/README.md
|
||||||
|
test/message.txt
|
||||||
|
test/testbootstrap.php
|
||||||
|
build/
|
||||||
|
vendor/
|
||||||
|
*.pem
|
||||||
|
composer.lock
|
||||||
|
.phpcs.xml
|
||||||
|
phpcs.xml
|
||||||
|
.phpcs-cache
|
||||||
|
/.rnd
|
||||||
|
test/PHPMailerTest.php*nonexistent_file.txt
|
||||||
|
test/*/PHPMailerTest.php*nonexistent_file.txt
|
||||||
|
phpunit.xml
|
||||||
|
/.phpunit.result.cache
|
41
php/PHP/fichier/php/PHP/PHPMailer/.phan/config.php
Normal file
41
php/PHP/fichier/php/PHP/PHPMailer/.phan/config.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configuration will be read and overlaid on top of the
|
||||||
|
* default configuration. Command line arguments will be applied
|
||||||
|
* after this file is read.
|
||||||
|
*/
|
||||||
|
return [
|
||||||
|
|
||||||
|
// A list of directories that should be parsed for class and
|
||||||
|
// method information. After excluding the directories
|
||||||
|
// defined in exclude_analysis_directory_list, the remaining
|
||||||
|
// files will be statically analyzed for errors.
|
||||||
|
//
|
||||||
|
// Thus, both first-party and third-party code being used by
|
||||||
|
// your application should be included in this list.
|
||||||
|
'directory_list' => [
|
||||||
|
'src',
|
||||||
|
'vendor',
|
||||||
|
'examples'
|
||||||
|
],
|
||||||
|
|
||||||
|
// A directory list that defines files that will be excluded
|
||||||
|
// from static analysis, but whose class and method
|
||||||
|
// information should be included.
|
||||||
|
//
|
||||||
|
// Generally, you'll want to include the directories for
|
||||||
|
// third-party code (such as "vendor/") in this list.
|
||||||
|
//
|
||||||
|
// n.b.: If you'd like to parse but not analyze 3rd
|
||||||
|
// party code, directories containing that code
|
||||||
|
// should be added to the `directory_list` as
|
||||||
|
// to `exclude_analysis_directory_list`.
|
||||||
|
"exclude_analysis_directory_list" => [
|
||||||
|
'vendor/'
|
||||||
|
],
|
||||||
|
|
||||||
|
'skip_slow_php_options_warning' => true,
|
||||||
|
|
||||||
|
'exclude_file_regex' => '@^vendor/.*/(tests|Tests)/@',
|
||||||
|
];
|
46
php/PHP/fichier/php/PHP/PHPMailer/COMMITMENT
Normal file
46
php/PHP/fichier/php/PHP/PHPMailer/COMMITMENT
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
GPL Cooperation Commitment
|
||||||
|
Version 1.0
|
||||||
|
|
||||||
|
Before filing or continuing to prosecute any legal proceeding or claim
|
||||||
|
(other than a Defensive Action) arising from termination of a Covered
|
||||||
|
License, we commit to extend to the person or entity ('you') accused
|
||||||
|
of violating the Covered License the following provisions regarding
|
||||||
|
cure and reinstatement, taken from GPL version 3. As used here, the
|
||||||
|
term 'this License' refers to the specific Covered License being
|
||||||
|
enforced.
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly
|
||||||
|
and finally terminates your license, and (b) permanently, if the
|
||||||
|
copyright holder fails to notify you of the violation by some
|
||||||
|
reasonable means prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you
|
||||||
|
have received notice of violation of this License (for any work)
|
||||||
|
from that copyright holder, and you cure the violation prior to 30
|
||||||
|
days after your receipt of the notice.
|
||||||
|
|
||||||
|
We intend this Commitment to be irrevocable, and binding and
|
||||||
|
enforceable against us and assignees of or successors to our
|
||||||
|
copyrights.
|
||||||
|
|
||||||
|
Definitions
|
||||||
|
|
||||||
|
'Covered License' means the GNU General Public License, version 2
|
||||||
|
(GPLv2), the GNU Lesser General Public License, version 2.1
|
||||||
|
(LGPLv2.1), or the GNU Library General Public License, version 2
|
||||||
|
(LGPLv2), all as published by the Free Software Foundation.
|
||||||
|
|
||||||
|
'Defensive Action' means a legal proceeding or claim that We bring
|
||||||
|
against you in response to a prior proceeding or claim initiated by
|
||||||
|
you or your affiliate.
|
||||||
|
|
||||||
|
'We' means each contributor to this repository as of the date of
|
||||||
|
inclusion of this file, including subsidiaries of a corporate
|
||||||
|
contributor.
|
||||||
|
|
||||||
|
This work is available under a Creative Commons Attribution-ShareAlike
|
||||||
|
4.0 International license (https://creativecommons.org/licenses/by-sa/4.0/).
|
502
php/PHP/fichier/php/PHP/PHPMailer/LICENSE
Normal file
502
php/PHP/fichier/php/PHP/PHPMailer/LICENSE
Normal file
File diff suppressed because it is too large
Load Diff
231
php/PHP/fichier/php/PHP/PHPMailer/README.md
Normal file
231
php/PHP/fichier/php/PHP/PHPMailer/README.md
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://supportukrainenow.org/)
|
||||||
|
|
||||||
|
![PHPMailer](https://raw.github.com/PHPMailer/PHPMailer/master/examples/images/phpmailer.png)
|
||||||
|
|
||||||
|
# PHPMailer – A full-featured email creation and transfer class for PHP
|
||||||
|
|
||||||
|
[![Test status](https://github.com/PHPMailer/PHPMailer/workflows/Tests/badge.svg)](https://github.com/PHPMailer/PHPMailer/actions)
|
||||||
|
[![codecov.io](https://codecov.io/gh/PHPMailer/PHPMailer/branch/master/graph/badge.svg?token=iORZpwmYmM)](https://codecov.io/gh/PHPMailer/PHPMailer)
|
||||||
|
[![Latest Stable Version](https://poser.pugx.org/phpmailer/phpmailer/v/stable.svg)](https://packagist.org/packages/phpmailer/phpmailer)
|
||||||
|
[![Total Downloads](https://poser.pugx.org/phpmailer/phpmailer/downloads)](https://packagist.org/packages/phpmailer/phpmailer)
|
||||||
|
[![License](https://poser.pugx.org/phpmailer/phpmailer/license.svg)](https://packagist.org/packages/phpmailer/phpmailer)
|
||||||
|
[![API Docs](https://github.com/phpmailer/phpmailer/workflows/Docs/badge.svg)](https://phpmailer.github.io/PHPMailer/)
|
||||||
|
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/PHPMailer/PHPMailer/badge)](https://api.securityscorecards.dev/projects/github.com/PHPMailer/PHPMailer)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Probably the world's most popular code for sending email from PHP!
|
||||||
|
- Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
|
||||||
|
- Integrated SMTP support – send without a local mail server
|
||||||
|
- Send emails with multiple To, CC, BCC, and Reply-to addresses
|
||||||
|
- Multipart/alternative emails for mail clients that do not read HTML email
|
||||||
|
- Add attachments, including inline
|
||||||
|
- Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
|
||||||
|
- SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over SMTPS and SMTP+STARTTLS transports
|
||||||
|
- Validates email addresses automatically
|
||||||
|
- Protects against header injection attacks
|
||||||
|
- Error messages in over 50 languages!
|
||||||
|
- DKIM and S/MIME signing support
|
||||||
|
- Compatible with PHP 5.5 and later, including PHP 8.2
|
||||||
|
- Namespaced to prevent name clashes
|
||||||
|
- Much more!
|
||||||
|
|
||||||
|
## Why you might need it
|
||||||
|
Many PHP developers need to send email from their code. The only PHP function that supports this directly is [`mail()`](https://www.php.net/manual/en/function.mail.php). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments.
|
||||||
|
|
||||||
|
Formatting email correctly is surprisingly difficult. There are myriad overlapping (and conflicting) standards, requiring tight adherence to horribly complicated formatting and encoding rules – the vast majority of code that you'll find online that uses the `mail()` function directly is just plain wrong, if not unsafe!
|
||||||
|
|
||||||
|
The PHP `mail()` function usually sends via a local mail server, typically fronted by a `sendmail` binary on Linux, BSD, and macOS platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP client allows email sending on all platforms without needing a local mail server. Be aware though, that the `mail()` function should be avoided when possible; it's both faster and [safer](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html) to use SMTP to localhost.
|
||||||
|
|
||||||
|
*Please* don't be tempted to do it yourself – if you don't use PHPMailer, there are many other excellent libraries that
|
||||||
|
you should look at before rolling your own. Try [SwiftMailer](https://swiftmailer.symfony.com/)
|
||||||
|
, [Laminas/Mail](https://docs.laminas.dev/laminas-mail/), [ZetaComponents](https://github.com/zetacomponents/Mail), etc.
|
||||||
|
|
||||||
|
## License
|
||||||
|
This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lgpl-2.1.html) license, along with the [GPL Cooperation Commitment](https://gplcc.github.io/gplcc/). Please read [LICENSE](https://github.com/PHPMailer/PHPMailer/blob/master/LICENSE) for information on the software availability and distribution.
|
||||||
|
|
||||||
|
## Installation & loading
|
||||||
|
PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), and installation via [Composer](https://getcomposer.org) is the recommended way to install PHPMailer. Just add this line to your `composer.json` file:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"phpmailer/phpmailer": "^6.9.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
or run
|
||||||
|
|
||||||
|
```sh
|
||||||
|
composer require phpmailer/phpmailer
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that the `vendor` folder and the `vendor/autoload.php` script are generated by Composer; they are not part of PHPMailer.
|
||||||
|
|
||||||
|
If you want to use XOAUTH2 authentication, you will also need to add a dependency on the `league/oauth2-client` and appropriate service adapters package in your `composer.json`, or take a look at
|
||||||
|
by @decomplexity's [SendOauth2 wrapper](https://github.com/decomplexity/SendOauth2), especially if you're using Microsoft services.
|
||||||
|
|
||||||
|
Alternatively, if you're not using Composer, you
|
||||||
|
can [download PHPMailer as a zip file](https://github.com/PHPMailer/PHPMailer/archive/master.zip), (note that docs and examples are not included in the zip file), then copy the contents of the PHPMailer folder into one of the `include_path` directories specified in your PHP configuration and load each class file manually:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
require 'path/to/PHPMailer/src/Exception.php';
|
||||||
|
require 'path/to/PHPMailer/src/PHPMailer.php';
|
||||||
|
require 'path/to/PHPMailer/src/SMTP.php';
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're not using the `SMTP` class explicitly (you're probably not), you don't need a `use` line for the SMTP class. Even if you're not using exceptions, you do still need to load the `Exception` class as it is used internally.
|
||||||
|
|
||||||
|
## Legacy versions
|
||||||
|
PHPMailer 5.2 (which is compatible with PHP 5.0 — 7.0) is no longer supported, even for security updates. You will find the latest version of 5.2 in the [5.2-stable branch](https://github.com/PHPMailer/PHPMailer/tree/5.2-stable). If you're using PHP 5.5 or later (which you should be), switch to the 6.x releases.
|
||||||
|
|
||||||
|
### Upgrading from 5.2
|
||||||
|
The biggest changes are that source files are now in the `src/` folder, and PHPMailer now declares the namespace `PHPMailer\PHPMailer`. This has several important effects – [read the upgrade guide](https://github.com/PHPMailer/PHPMailer/tree/master/UPGRADING.md) for more details.
|
||||||
|
|
||||||
|
### Minimal installation
|
||||||
|
While installing the entire package manually or with Composer is simple, convenient, and reliable, you may want to include only vital files in your project. At the very least you will need [src/PHPMailer.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/PHPMailer.php). If you're using SMTP, you'll need [src/SMTP.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/SMTP.php), and if you're using POP-before SMTP (*very* unlikely!), you'll need [src/POP3.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/POP3.php). You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder if you're not showing errors to users and can make do with English-only errors. If you're using XOAUTH2 you will need [src/OAuth.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/OAuth.php) as well as the Composer dependencies for the services you wish to authenticate with. Really, it's much easier to use Composer!
|
||||||
|
|
||||||
|
## A Simple Example
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
//These must be at the top of your script, not inside a function
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
//Load Composer's autoloader
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create an instance; passing `true` enables exceptions
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
//Server settings
|
||||||
|
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
|
||||||
|
$mail->isSMTP(); //Send using SMTP
|
||||||
|
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
|
||||||
|
$mail->SMTPAuth = true; //Enable SMTP authentication
|
||||||
|
$mail->Username = 'user@example.com'; //SMTP username
|
||||||
|
$mail->Password = 'secret'; //SMTP password
|
||||||
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
|
||||||
|
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
||||||
|
|
||||||
|
//Recipients
|
||||||
|
$mail->setFrom('from@example.com', 'Mailer');
|
||||||
|
$mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient
|
||||||
|
$mail->addAddress('ellen@example.com'); //Name is optional
|
||||||
|
$mail->addReplyTo('info@example.com', 'Information');
|
||||||
|
$mail->addCC('cc@example.com');
|
||||||
|
$mail->addBCC('bcc@example.com');
|
||||||
|
|
||||||
|
//Attachments
|
||||||
|
$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
|
||||||
|
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
|
||||||
|
|
||||||
|
//Content
|
||||||
|
$mail->isHTML(true); //Set email format to HTML
|
||||||
|
$mail->Subject = 'Here is the subject';
|
||||||
|
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
|
||||||
|
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||||
|
|
||||||
|
$mail->send();
|
||||||
|
echo 'Message has been sent';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You'll find plenty to play with in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder, which covers many common scenarios including sending through Gmail, building contact forms, sending to mailing lists, and more.
|
||||||
|
|
||||||
|
If you are re-using the instance (e.g. when sending to a mailing list), you may need to clear the recipient list to avoid sending duplicate messages. See [the mailing list example](https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps) for further guidance.
|
||||||
|
|
||||||
|
That's it. You should now be ready to use PHPMailer!
|
||||||
|
|
||||||
|
## Localization
|
||||||
|
PHPMailer defaults to English, but in the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder, you'll find many translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this:
|
||||||
|
|
||||||
|
```php
|
||||||
|
//To load the French version
|
||||||
|
$mail->setLanguage('fr', '/optional/path/to/language/directory/');
|
||||||
|
```
|
||||||
|
|
||||||
|
We welcome corrections and new languages – if you're looking for corrections, run the [Language/TranslationCompletenessTest.php](https://github.com/PHPMailer/PHPMailer/blob/master/test/Language/TranslationCompletenessTest.php) script in the tests folder and it will show any missing translations.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
Start reading at the [GitHub wiki](https://github.com/PHPMailer/PHPMailer/wiki). If you're having trouble, head for [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) as it's frequently updated.
|
||||||
|
|
||||||
|
Examples of how to use PHPMailer for common scenarios can be found in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder. If you're looking for a good starting point, we recommend you start with [the Gmail example](https://github.com/PHPMailer/PHPMailer/tree/master/examples/gmail.phps).
|
||||||
|
|
||||||
|
To reduce PHPMailer's deployed code footprint, examples are not included if you load PHPMailer via Composer or via [GitHub's zip file download](https://github.com/PHPMailer/PHPMailer/archive/master.zip), so you'll need to either clone the git repository or use the above links to get to the examples directly.
|
||||||
|
|
||||||
|
Complete generated API documentation is [available online](https://phpmailer.github.io/PHPMailer/).
|
||||||
|
|
||||||
|
You can generate complete API-level documentation by running `phpdoc` in the top-level folder, and documentation will appear in the `docs` folder, though you'll need to have [PHPDocumentor](http://www.phpdoc.org) installed. You may find [the unit tests](https://github.com/PHPMailer/PHPMailer/blob/master/test/PHPMailerTest.php) a good reference for how to do various operations such as encryption.
|
||||||
|
|
||||||
|
If the documentation doesn't cover what you need, search the [many questions on Stack Overflow](http://stackoverflow.com/questions/tagged/phpmailer), and before you ask a question about "SMTP Error: Could not connect to SMTP host.", [read the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting).
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
[PHPMailer tests](https://github.com/PHPMailer/PHPMailer/tree/master/test/) use PHPUnit 9, with [a polyfill](https://github.com/Yoast/PHPUnit-Polyfills) to let 9-style tests run on older PHPUnit and PHP versions.
|
||||||
|
|
||||||
|
[![Test status](https://github.com/PHPMailer/PHPMailer/workflows/Tests/badge.svg)](https://github.com/PHPMailer/PHPMailer/actions)
|
||||||
|
|
||||||
|
If this isn't passing, is there something you can do to help?
|
||||||
|
|
||||||
|
## Security
|
||||||
|
Please disclose any vulnerabilities found responsibly – report security issues to the maintainers privately.
|
||||||
|
|
||||||
|
See [SECURITY](https://github.com/PHPMailer/PHPMailer/tree/master/SECURITY.md) and [PHPMailer's security advisories on GitHub](https://github.com/PHPMailer/PHPMailer/security).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
Please submit bug reports, suggestions, and pull requests to the [GitHub issue tracker](https://github.com/PHPMailer/PHPMailer/issues).
|
||||||
|
|
||||||
|
We're particularly interested in fixing edge cases, expanding test coverage, and updating translations.
|
||||||
|
|
||||||
|
If you found a mistake in the docs, or want to add something, go ahead and amend the wiki – anyone can edit it.
|
||||||
|
|
||||||
|
If you have git clones from prior to the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git remote set-url upstream https://github.com/PHPMailer/PHPMailer.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Please *don't* use the SourceForge or Google Code projects any more; they are obsolete and no longer maintained.
|
||||||
|
|
||||||
|
## Sponsorship
|
||||||
|
Development time and resources for PHPMailer are provided by [Smartmessages.net](https://info.smartmessages.net/), the world's only privacy-first email marketing system.
|
||||||
|
|
||||||
|
<a href="https://info.smartmessages.net/"><img src="https://www.smartmessages.net/img/smartmessages-logo.svg" width="550" alt="Smartmessages.net privacy-first email marketing logo"></a>
|
||||||
|
|
||||||
|
Donations are very welcome, whether in beer 🍺, T-shirts 👕, or cold, hard cash 💰. Sponsorship through GitHub is a simple and convenient way to say "thank you" to PHPMailer's maintainers and contributors – just click the "Sponsor" button [on the project page](https://github.com/PHPMailer/PHPMailer). If your company uses PHPMailer, consider taking part in Tidelift's enterprise support programme.
|
||||||
|
|
||||||
|
## PHPMailer For Enterprise
|
||||||
|
|
||||||
|
Available as part of the Tidelift Subscription.
|
||||||
|
|
||||||
|
The maintainers of PHPMailer and thousands of other packages are working with Tidelift to deliver commercial
|
||||||
|
support and maintenance for the open-source packages you use to build your applications. Save time, reduce risk, and
|
||||||
|
improve code health, while paying the maintainers of the exact packages you
|
||||||
|
use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-phpmailer-phpmailer?utm_source=packagist-phpmailer-phpmailer&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
See [changelog](changelog.md).
|
||||||
|
|
||||||
|
## History
|
||||||
|
- PHPMailer was originally written in 2001 by Brent R. Matzelle as a [SourceForge project](http://sourceforge.net/projects/phpmailer/).
|
||||||
|
- [Marcus Bointon](https://github.com/Synchro) (`coolbru` on SF) and Andy Prevost (`codeworxtech`) took over the project in 2004.
|
||||||
|
- Became an Apache incubator project on Google Code in 2010, managed by Jim Jagielski.
|
||||||
|
- Marcus created [his fork on GitHub](https://github.com/Synchro/PHPMailer) in 2008.
|
||||||
|
- Jim and Marcus decide to join forces and use GitHub as the canonical and official repo for PHPMailer in 2013.
|
||||||
|
- PHPMailer moves to [the PHPMailer organisation](https://github.com/PHPMailer) on GitHub in 2013.
|
||||||
|
|
||||||
|
### What's changed since moving from SourceForge?
|
||||||
|
- Official successor to the SourceForge and Google Code projects.
|
||||||
|
- Test suite.
|
||||||
|
- Continuous integration with GitHub Actions.
|
||||||
|
- Composer support.
|
||||||
|
- Public development.
|
||||||
|
- Additional languages and language strings.
|
||||||
|
- CRAM-MD5 authentication support.
|
||||||
|
- Preserves full repo history of authors, commits, and branches from the original SourceForge project.
|
37
php/PHP/fichier/php/PHP/PHPMailer/SECURITY.md
Normal file
37
php/PHP/fichier/php/PHP/PHPMailer/SECURITY.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Security notices relating to PHPMailer
|
||||||
|
|
||||||
|
Please disclose any security issues or vulnerabilities found through [Tidelift's coordinated disclosure system](https://tidelift.com/security) or to the maintainers privately.
|
||||||
|
|
||||||
|
PHPMailer 6.4.1 and earlier contain a vulnerability that can result in untrusted code being called (if such code is injected into the host project's scope by other means). If the `$patternselect` parameter to `validateAddress()` is set to `'php'` (the default, defined by `PHPMailer::$validator`), and the global namespace contains a function called `php`, it will be called in preference to the built-in validator of the same name. Mitigated in PHPMailer 6.5.0 by denying the use of simple strings as validator function names. Recorded as [CVE-2021-3603](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2021-3603). Reported by [Vikrant Singh Chauhan](mailto:vi@hackberry.xyz) via [huntr.dev](https://www.huntr.dev/).
|
||||||
|
|
||||||
|
PHPMailer versions 6.4.1 and earlier contain a possible remote code execution vulnerability through the `$lang_path` parameter of the `setLanguage()` method. If the `$lang_path` parameter is passed unfiltered from user input, it can be set to [a UNC path](https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats#unc-paths), and if an attacker is also able to persuade the server to load a file from that UNC path, a script file under their control may be executed. This vulnerability only applies to systems that resolve UNC paths, typically only Microsoft Windows.
|
||||||
|
PHPMailer 6.5.0 mitigates this by no longer treating translation files as PHP code, but by parsing their text content directly. This approach avoids the possibility of executing unknown code while retaining backward compatibility. This isn't ideal, so the current translation format is deprecated and will be replaced in the next major release. Recorded as [CVE-2021-34551](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2021-34551). Reported by [Jilin Diting Information Technology Co., Ltd](https://listensec.com) via Tidelift.
|
||||||
|
|
||||||
|
PHPMailer versions between 6.1.8 and 6.4.0 contain a regression of the earlier CVE-2018-19296 object injection vulnerability as a result of [a fix for Windows UNC paths in 6.1.8](https://github.com/PHPMailer/PHPMailer/commit/e2e07a355ee8ff36aba21d0242c5950c56e4c6f9). Recorded as [CVE-2020-36326](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-36326). Reported by Fariskhi Vidyan via Tidelift. 6.4.1 fixes this issue, and also enforces stricter checks for URL schemes in local path contexts.
|
||||||
|
|
||||||
|
PHPMailer versions 6.1.5 and earlier contain an output escaping bug that occurs in `Content-Type` and `Content-Disposition` when filenames passed into `addAttachment` and other methods that accept attachment names contain double quote characters, in contravention of RFC822 3.4.1. No specific vulnerability has been found relating to this, but it could allow file attachments to bypass attachment filters that are based on matching filename extensions. Recorded as [CVE-2020-13625](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-13625). Reported by Elar Lang of Clarified Security.
|
||||||
|
|
||||||
|
PHPMailer versions prior to 6.0.6 and 5.2.27 are vulnerable to an object injection attack by passing `phar://` paths into `addAttachment()` and other functions that may receive unfiltered local paths, possibly leading to RCE. Recorded as [CVE-2018-19296](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2018-19296). See [this article](https://knasmueller.net/5-answers-about-php-phar-exploitation) for more info on this type of vulnerability. Mitigated by blocking the use of paths containing URL-protocol style prefixes such as `phar://`. Reported by Sehun Oh of cyberone.kr.
|
||||||
|
|
||||||
|
PHPMailer versions prior to 5.2.24 (released July 26th 2017) have an XSS vulnerability in one of the code examples, [CVE-2017-11503](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2017-11503). The `code_generator.phps` example did not filter user input prior to output. This file is distributed with a `.phps` extension, so it it not normally executable unless it is explicitly renamed, and the file is not included when PHPMailer is loaded through composer, so it is safe by default. There was also an undisclosed potential XSS vulnerability in the default exception handler (unused by default). Patches for both issues kindly provided by Patrick Monnerat of the Fedora Project.
|
||||||
|
|
||||||
|
PHPMailer versions prior to 5.2.22 (released January 9th 2017) have a local file disclosure vulnerability, [CVE-2017-5223](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2017-5223). If content passed into `msgHTML()` is sourced from unfiltered user input, relative paths can map to absolute local file paths and added as attachments. Also note that `addAttachment` (just like `file_get_contents`, `passthru`, `unlink`, etc) should not be passed user-sourced params either! Reported by Yongxiang Li of Asiasecurity.
|
||||||
|
|
||||||
|
PHPMailer versions prior to 5.2.20 (released December 28th 2016) are vulnerable to [CVE-2016-10045](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-10045) a remote code execution vulnerability, responsibly reported by [Dawid Golunski](https://legalhackers.com/advisories/PHPMailer-Exploit-Remote-Code-Exec-CVE-2016-10045-Vuln-Patch-Bypass.html), and patched by Paul Buonopane (@Zenexer).
|
||||||
|
|
||||||
|
PHPMailer versions prior to 5.2.18 (released December 2016) are vulnerable to [CVE-2016-10033](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-10033) a remote code execution vulnerability, responsibly reported by [Dawid Golunski](http://legalhackers.com/advisories/PHPMailer-Exploit-Remote-Code-Exec-CVE-2016-10033-Vuln.html).
|
||||||
|
|
||||||
|
PHPMailer versions prior to 5.2.14 (released November 2015) are vulnerable to [CVE-2015-8476](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2015-8476) an SMTP CRLF injection bug permitting arbitrary message sending.
|
||||||
|
|
||||||
|
PHPMailer versions prior to 5.2.10 (released May 2015) are vulnerable to [CVE-2008-5619](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2008-5619), a remote code execution vulnerability in the bundled html2text library. This file was removed in 5.2.10, so if you are using a version prior to that and make use of the html2text function, it's vitally important that you upgrade and remove this file.
|
||||||
|
|
||||||
|
PHPMailer versions prior to 2.0.7 and 2.2.1 are vulnerable to [CVE-2012-0796](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2012-0796), an email header injection attack.
|
||||||
|
|
||||||
|
Joomla 1.6.0 uses PHPMailer in an unsafe way, allowing it to reveal local file paths, reported in [CVE-2011-3747](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3747).
|
||||||
|
|
||||||
|
PHPMailer didn't sanitise the `$lang_path` parameter in `SetLanguage`. This wasn't a problem in itself, but some apps (PHPClassifieds, ATutor) also failed to sanitise user-provided parameters passed to it, permitting semi-arbitrary local file inclusion, reported in [CVE-2010-4914](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-4914), [CVE-2007-2021](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2007-2021) and [CVE-2006-5734](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2006-5734).
|
||||||
|
|
||||||
|
PHPMailer 1.7.2 and earlier contained a possible DDoS vulnerability reported in [CVE-2005-1807](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2005-1807).
|
||||||
|
|
||||||
|
PHPMailer 1.7 and earlier (June 2003) have a possible vulnerability in the `SendmailSend` method where shell commands may not be sanitised. Reported in [CVE-2007-3215](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2007-3215).
|
||||||
|
|
125
php/PHP/fichier/php/PHP/PHPMailer/UPGRADING.md
Normal file
125
php/PHP/fichier/php/PHP/PHPMailer/UPGRADING.md
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
# Upgrading from PHPMailer 5.2 to 6.0
|
||||||
|
|
||||||
|
PHPMailer 6.0 is a major update, breaking backward compatibility.
|
||||||
|
|
||||||
|
If you're in doubt about how you should be using PHPMailer 6, take a look at the examples as they have all been updated to work in a PHPMailer 6.0 style.
|
||||||
|
|
||||||
|
## PHP Version
|
||||||
|
|
||||||
|
PHPMailer 6.0 requires PHP 5.5 or later, and is fully compatible with PHP 7.0. PHPMailer 5.2 supported PHP 5.0 and upwards, so if you need to run on a legacy PHP version, see the [PHPMailer 5.2-stable branch on Github](https://github.com/PHPMailer/PHPMailer/tree/5.2-stable).
|
||||||
|
|
||||||
|
## Loading PHPMailer
|
||||||
|
|
||||||
|
The single biggest change will be in the way that you load PHPMailer. In earlier versions you may have done this:
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'PHPMailerAutoload.php';
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'class.phpmailer.php';
|
||||||
|
require 'class.smtp.php';
|
||||||
|
```
|
||||||
|
|
||||||
|
We recommend that you load PHPMailer via composer, using its standard autoloader, which you probably won't need to load if you're using it already, but in case you're not, you will need to do this instead:
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're not using composer, you can still load the classes manually, depending on what you're using:
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'src/PHPMailer.php';
|
||||||
|
require 'src/SMTP.php';
|
||||||
|
require 'src/Exception.php';
|
||||||
|
```
|
||||||
|
|
||||||
|
## Namespace
|
||||||
|
PHPMailer 6 uses a [namespace](http://php.net/manual/en/language.namespaces.rationale.php) of `PHPMailer\PHPMailer`, because it's the PHPMailer project within the PHPMailer organisation. You **must** import (with a `use` statement) classes you're using explicitly into your own namespace, or reference them absolutely in the global namespace - all the examples do this. This means the fully-qualified name of the main PHPMailer class is `PHPMailer\PHPMailer\PHPMailer`, which is a bit of a mouthful, but there's no harm in it! If you are using other PHPMailer classes explicitly (such as `SMTP` or `Exception`), you will need to import them into your namespace too.
|
||||||
|
|
||||||
|
For example you might create an instance like this:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
namespace MyProject;
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
$mail = new PHPMailer;
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
or alternatively, using a fully qualified name:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
namespace MyProject;
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
$mail = new PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that `use` statements apply *only* to the file they appear in (they are local aliases), so if an included file contains `use` statements, it will not import the namespaced classes into the file you're including from.
|
||||||
|
|
||||||
|
## Namespaced exceptions
|
||||||
|
PHPMailer now uses its own namespaced `Exception` class, so if you were previously catching exceptions of type `phpmailerException` (or subclasses of that), you will need to update them to use the PHPMailer namespace, and make any existing `Exception` references use the global namespace, i.e. `\Exception`. If your original code was:
|
||||||
|
|
||||||
|
```php
|
||||||
|
try {
|
||||||
|
...
|
||||||
|
} catch (phpmailerException $e) {
|
||||||
|
echo $e->errorMessage();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Convert it to:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
...
|
||||||
|
try {
|
||||||
|
...
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->errorMessage();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## OAuth2 Support
|
||||||
|
The OAuth2 implementation has been completely redesigned using the [OAuth2 packages](http://oauth2-client.thephpleague.com) from the [League of extraordinary packages](http://thephpleague.com), providing support for many more OAuth services, and you'll need to update your code if you were using OAuth in 5.2. See [the examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) and documentation in the [PHPMailer wiki](https://github.com/PHPMailer/PHPMailer/wiki).
|
||||||
|
|
||||||
|
## Extras
|
||||||
|
Additional classes previously bundled in the `Extras` folder (such as htmlfilter and EasyPeasyICS) have been removed - use equivalent packages from [packagist.org](https://packagist.org) instead.
|
||||||
|
|
||||||
|
## Other upgrade changes
|
||||||
|
See the changelog for full details.
|
||||||
|
* File structure simplified, classes live in the `src/` folder
|
||||||
|
* Most statically called functions now use the `static` keyword instead of `self`, so it's possible to override static internal functions in subclasses, for example `validateAddress()`
|
||||||
|
* Complete RFC standardisation on CRLF (`\r\n`) line breaks by default:
|
||||||
|
* `PHPMailer::$LE` still exists, but all uses of it are changed to `static::$LE` for easier overriding. It may be changed to `\n` automatically when sending via `mail()` on UNIX-like OSs
|
||||||
|
* `PHPMailer::CRLF` line ending constant removed
|
||||||
|
* The length of the line break is no longer used in line length calculations
|
||||||
|
* Similar changes to line break handling in SMTP and POP3 classes
|
||||||
|
* All elements previously marked as deprecated have been removed:
|
||||||
|
* `PHPMailer->Version`
|
||||||
|
* `PHPMailer->ReturnPath`
|
||||||
|
* `PHPMailer->PluginDir`
|
||||||
|
* `PHPMailer->encodeQPphp()`
|
||||||
|
* `SMTP->CRLF`
|
||||||
|
* `SMTP->Version`
|
||||||
|
* `SMTP->SMTP_PORT`
|
||||||
|
* `POP3->CRLF`
|
||||||
|
* `POP3->Version`
|
||||||
|
* NTLM authentication has been removed - it never worked anyway!
|
||||||
|
* `PHPMailer->Workstation`
|
||||||
|
* `PHPMailer->Realm`
|
||||||
|
* `SMTP::authenticate` method signature changed
|
||||||
|
* `parseAddresses()` is now static
|
||||||
|
* `validateAddress()` is now called statically from `parseAddresses()`
|
||||||
|
* `idnSupported()` is now static and is called statically from `punyencodeAddress()`
|
||||||
|
* `PHPMailer->SingleToArray` is now protected
|
1
php/PHP/fichier/php/PHP/PHPMailer/VERSION
Normal file
1
php/PHP/fichier/php/PHP/PHPMailer/VERSION
Normal file
@ -0,0 +1 @@
|
|||||||
|
6.9.1
|
1064
php/PHP/fichier/php/PHP/PHPMailer/changelog.md
Normal file
1064
php/PHP/fichier/php/PHP/PHPMailer/changelog.md
Normal file
File diff suppressed because it is too large
Load Diff
79
php/PHP/fichier/php/PHP/PHPMailer/composer.json
Normal file
79
php/PHP/fichier/php/PHP/PHPMailer/composer.json
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"name": "phpmailer/phpmailer",
|
||||||
|
"type": "library",
|
||||||
|
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Marcus Bointon",
|
||||||
|
"email": "phpmailer@synchromedia.co.uk"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jim Jagielski",
|
||||||
|
"email": "jimjag@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Andy Prevost",
|
||||||
|
"email": "codeworxtech@users.sourceforge.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Brent R. Matzelle"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/Synchro",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.5.0",
|
||||||
|
"ext-ctype": "*",
|
||||||
|
"ext-filter": "*",
|
||||||
|
"ext-hash": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
|
||||||
|
"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",
|
||||||
|
"roave/security-advisories": "dev-latest",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7.2",
|
||||||
|
"yoast/phpunit-polyfills": "^1.0.4"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication",
|
||||||
|
"ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
|
||||||
|
"ext-openssl": "Needed for secure SMTP sending and DKIM signing",
|
||||||
|
"greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication",
|
||||||
|
"hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
|
||||||
|
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
|
||||||
|
"psr/log": "For optional PSR-3 debug logging",
|
||||||
|
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication",
|
||||||
|
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"PHPMailer\\PHPMailer\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"PHPMailer\\Test\\": "test/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"license": "LGPL-2.1-only",
|
||||||
|
"scripts": {
|
||||||
|
"check": "./vendor/bin/phpcs",
|
||||||
|
"test": "./vendor/bin/phpunit --no-coverage",
|
||||||
|
"coverage": "./vendor/bin/phpunit",
|
||||||
|
"lint": [
|
||||||
|
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . --show-deprecated -e php,phps --exclude vendor --exclude .git --exclude build"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
9
php/PHP/fichier/php/PHP/PHPMailer/docs/README.md
Normal file
9
php/PHP/fichier/php/PHP/PHPMailer/docs/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# PHPMailer Documentation
|
||||||
|
|
||||||
|
Generated documentation for PHPMailer is [available online](https://phpmailer.github.io/PHPMailer/), and is regenerated automatically whenever changes are made.
|
||||||
|
|
||||||
|
Pre-built PHPMailer API documentation is not provided in this repo, but you can generate it by running `phpdoc` in the top-level folder of this project, and documentation will be generated in this `docs` folder. You will need to have [phpDocumentor](https://www.phpdoc.org) installed. The configuration for phpdoc is in the [phpdoc.dist.xml file](https://github.com/PHPMailer/PHPMailer/blob/master/phpdoc.dist.xml).
|
||||||
|
|
||||||
|
Further help and information is available in [the PHPMailer README](https://github.com/PHPMailer/PHPMailer/blob/master/README.md), [the examples folder](https://github.com/PHPMailer/PHPMailer/tree/master/examples), and in [the GitHub wiki](https://github.com/PHPMailer/PHPMailer/wiki).
|
||||||
|
|
||||||
|
Fixes and additions to documentation are welcome - please submit pull requests or improve wiki pages.
|
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This shows how to make a new public/private key pair suitable for use with DKIM.
|
||||||
|
* You should only need to do this once, and the public key (**not** the private key!)
|
||||||
|
* you generate should be inserted in your DNS matching the selector you want.
|
||||||
|
*
|
||||||
|
* You can also use the DKIM wizard here: https://www.sparkpost.com/resources/tools/dkim-wizard/
|
||||||
|
* but be aware that having your private key known anywhere outside your own server
|
||||||
|
* is a security risk, and it's easy enough to create your own on your own server.
|
||||||
|
*
|
||||||
|
* For security, any keys you create should not be accessible via your web site.
|
||||||
|
*
|
||||||
|
* 2048 bits is the recommended minimum key length - gmail won't accept less than 1024 bits.
|
||||||
|
* To test your DKIM config, use Sparkpost's DKIM tester:
|
||||||
|
* https://tools.sparkpost.com/dkim
|
||||||
|
*
|
||||||
|
* Note that you only need a *private* key to *send* a DKIM-signed message,
|
||||||
|
* but receivers need your *public* key in order to verify it.
|
||||||
|
*
|
||||||
|
* Your public key will need to be formatted appropriately for your DNS and
|
||||||
|
* inserted there using the selector you want to use.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Set these to match your domain and chosen DKIM selector
|
||||||
|
$domain = 'example.com';
|
||||||
|
$selector = 'phpmailer';
|
||||||
|
|
||||||
|
//Private key filename for this selector
|
||||||
|
$privatekeyfile = $selector . '_dkim_private.pem';
|
||||||
|
//Public key filename for this selector
|
||||||
|
$publickeyfile = $selector . '_dkim_public.pem';
|
||||||
|
|
||||||
|
if (file_exists($privatekeyfile)) {
|
||||||
|
echo "Using existing keys - if you want to generate new keys, delete old key files first.\n\n";
|
||||||
|
$privatekey = file_get_contents($privatekeyfile);
|
||||||
|
$publickey = file_get_contents($publickeyfile);
|
||||||
|
} else {
|
||||||
|
//Create a 2048-bit RSA key with an SHA256 digest
|
||||||
|
$pk = openssl_pkey_new(
|
||||||
|
[
|
||||||
|
'digest_alg' => 'sha256',
|
||||||
|
'private_key_bits' => 2048,
|
||||||
|
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
//Save private key
|
||||||
|
openssl_pkey_export_to_file($pk, $privatekeyfile);
|
||||||
|
//Save public key
|
||||||
|
$pubKey = openssl_pkey_get_details($pk);
|
||||||
|
$publickey = $pubKey['key'];
|
||||||
|
file_put_contents($publickeyfile, $publickey);
|
||||||
|
$privatekey = file_get_contents($privatekeyfile);
|
||||||
|
}
|
||||||
|
echo "Private key (keep this private!):\n\n" . $privatekey;
|
||||||
|
echo "\n\nPublic key:\n\n" . $publickey;
|
||||||
|
|
||||||
|
//Prepare public key for DNS, e.g.
|
||||||
|
//phpmailer._domainkey.example.com IN TXT "v=DKIM1; h=sha256; t=s; p=" "MIIBIjANBg...oXlwIDAQAB"...
|
||||||
|
$dnskey = "$selector._domainkey.$domain IN TXT";
|
||||||
|
$dnsvalue = '"v=DKIM1; h=sha256; t=s; p=" ';
|
||||||
|
//Some DNS servers don't like ;(semi colon) chars unless backslash-escaped
|
||||||
|
$dnsvalue2 = '"v=DKIM1\; h=sha256\; t=s\; p=" ';
|
||||||
|
|
||||||
|
//Strip and split the key into smaller parts and format for DNS
|
||||||
|
//Many DNS systems don't like long TXT entries
|
||||||
|
//but are OK if it's split into 255-char chunks
|
||||||
|
//Remove PEM wrapper
|
||||||
|
$publickey = preg_replace('/^-+.*?-+$/m', '', $publickey);
|
||||||
|
//Strip line breaks
|
||||||
|
$publickey = str_replace(["\r", "\n"], '', $publickey);
|
||||||
|
//Split into chunks
|
||||||
|
$keyparts = str_split($publickey, 253); //Becomes 255 when quotes are included
|
||||||
|
//Quote each chunk
|
||||||
|
foreach ($keyparts as $keypart) {
|
||||||
|
$dnsvalue .= '"' . trim($keypart) . '" ';
|
||||||
|
$dnsvalue2 .= '"' . trim($keypart) . '" ';
|
||||||
|
}
|
||||||
|
echo "\n\nDNS key:\n\n" . trim($dnskey);
|
||||||
|
echo "\n\nDNS value:\n\n" . trim($dnsvalue);
|
||||||
|
echo "\n\nDNS value (with escaping):\n\n" . trim($dnsvalue2);
|
46
php/PHP/fichier/php/PHP/PHPMailer/examples/DKIM_sign.phps
Normal file
46
php/PHP/fichier/php/PHP/PHPMailer/examples/DKIM_sign.phps
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows sending a DKIM-signed message with PHPMailer.
|
||||||
|
* More info about DKIM can be found here: http://www.dkim.org/info/dkim-faq.html
|
||||||
|
* There's more to using DKIM than just this code - check out this article:
|
||||||
|
* @see https://yomotherboard.com/how-to-setup-email-server-dkim-keys/
|
||||||
|
* See also the DKIM_gen_keys example code in the examples folder,
|
||||||
|
* which shows how to make a key pair from PHP.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import the PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Usual setup
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
$mail->Subject = 'PHPMailer mail() test';
|
||||||
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
||||||
|
|
||||||
|
//This should be the same as the domain of your From address
|
||||||
|
$mail->DKIM_domain = 'example.com';
|
||||||
|
//See the DKIM_gen_keys.phps script for making a key pair -
|
||||||
|
//here we assume you've already done that.
|
||||||
|
//Path to your private key:
|
||||||
|
$mail->DKIM_private = 'dkim_private.pem';
|
||||||
|
//Set this to your own selector
|
||||||
|
$mail->DKIM_selector = 'phpmailer';
|
||||||
|
//Put your private key's passphrase in here if it has one
|
||||||
|
$mail->DKIM_passphrase = '';
|
||||||
|
//The identity you're signing as - usually your From address
|
||||||
|
$mail->DKIM_identity = $mail->From;
|
||||||
|
//Suppress listing signed header fields in signature, defaults to true for debugging purpose
|
||||||
|
$mail->DKIM_copyHeaderFields = false;
|
||||||
|
//Optionally you can add extra headers for signing to meet special requirements
|
||||||
|
$mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
|
||||||
|
|
||||||
|
//When you send, the DKIM settings will be used to sign the message
|
||||||
|
if (!$mail->send()) {
|
||||||
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
echo 'Message sent!';
|
||||||
|
}
|
95
php/PHP/fichier/php/PHP/PHPMailer/examples/README.md
Normal file
95
php/PHP/fichier/php/PHP/PHPMailer/examples/README.md
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
[![PHPMailer logo](images/phpmailer.png)](https://github.com/PHPMailer/PHPMailer)
|
||||||
|
# PHPMailer code examples
|
||||||
|
|
||||||
|
This folder contains a collection of examples of using [PHPMailer](https://github.com/PHPMailer/PHPMailer).
|
||||||
|
|
||||||
|
## About testing email sending
|
||||||
|
|
||||||
|
When working on email sending code you'll find yourself worrying about what might happen if all these test emails got sent to your mailing list. The solution is to use a fake mail server, one that acts just like the real thing, but just doesn't actually send anything out. Some offer web interfaces, feedback, logging, the ability to return specific error codes, all things that are useful for testing error handling, authentication etc. Here's a selection of mail testing tools you might like to try:
|
||||||
|
|
||||||
|
* [FakeEmail](https://github.com/tomwardill/FakeEmail), a Python-based fake mail server with a web interface.
|
||||||
|
* [smtp-sink](http://www.postfix.org/smtp-sink.1.html), part of the Postfix mail server, so you may have this installed already. This is used in the Travis-CI configuration to run PHPMailer's unit tests.
|
||||||
|
* [smtp4dev](https://github.com/rnwood/smtp4dev), a dummy SMTP server for Windows and Linux.
|
||||||
|
* [fakesendmail.sh](https://github.com/PHPMailer/PHPMailer/blob/master/test/fakesendmail.sh), part of PHPMailer's test setup, this is a shell script that emulates sendmail for testing 'mail' or 'sendmail' methods in PHPMailer.
|
||||||
|
* [HELO](https://usehelo.com), a very nice (commercial) mail server desktop app from BeyondCode, and [how to set it up for local testing](https://usehelo.com/blog/how-to-use-helo-with-phps-mail-function).
|
||||||
|
* [msglint](http://tools.ietf.org/tools/msglint/), not a mail server, the IETF's MIME structure analyser checks the formatting of your messages.
|
||||||
|
* [MailHog](https://github.com/les-enovateurs/mailhog-examples), a Go-based email testing tool for developers with a web interface. You can use it with Docker and GitHub Actions to test your mails. The repository also contains a small part of PHPMailer's setup.
|
||||||
|
|
||||||
|
Most of these examples use the `example.com` and `example.net` domains. These domains are reserved by IANA for illustrative purposes, as documented in [RFC 2606](http://tools.ietf.org/html/rfc2606). Don't use made-up domains like 'mydomain.com' or 'somedomain.com' in examples as someone, somewhere, probably owns them!
|
||||||
|
|
||||||
|
## Security note
|
||||||
|
Before running these examples in a web server, you'll need to rename them with '.php' extensions. They are supplied as '.phps' files which will usually be displayed with syntax highlighting by PHP instead of running them. This prevents potential security issues with running potential spam-gateway code if you happen to deploy these code examples on a live site - _please don't do that!_
|
||||||
|
|
||||||
|
Similarly, don't leave your passwords in these files as they will be visible to the world!
|
||||||
|
|
||||||
|
## [mail.phps](mail.phps)
|
||||||
|
|
||||||
|
This is a basic example which creates an email message from an external HTML file, creates a plain text body, sets various addresses, adds an attachment and sends the message. It uses PHP's built-in mail() function which is the simplest to use, but relies on the presence of a local mail server, something which is not usually available on Windows. If you find yourself in that situation, either install a local mail server, or use a remote one and send using SMTP instead.
|
||||||
|
|
||||||
|
## [simple_contact_form.phps](simple_contact_form.phps)
|
||||||
|
|
||||||
|
This is probably the most common reason for using PHPMailer - building a contact form. This example has a basic, unstyled form and also illustrates how to filter input data before using it, how to validate addresses, how to avoid being abused as a spam gateway, and how to address messages correctly so that you don't fail SPF checks.
|
||||||
|
|
||||||
|
## [exceptions.phps](exceptions.phps)
|
||||||
|
|
||||||
|
Like the mail example, but shows how to use PHPMailer's optional exceptions for error handling.
|
||||||
|
|
||||||
|
## [extending.phps](extending.phps)
|
||||||
|
|
||||||
|
This shows how to create a subclass of PHPMailer to customise its behaviour and simplify coding in your app.
|
||||||
|
|
||||||
|
## [smtp.phps](smtp.phps)
|
||||||
|
|
||||||
|
A simple example sending using SMTP with authentication.
|
||||||
|
|
||||||
|
## [smtp_no_auth.phps](smtp_no_auth.phps)
|
||||||
|
|
||||||
|
A simple example sending using SMTP without authentication.
|
||||||
|
|
||||||
|
## [send_file_upload.phps](send_file_upload.phps)
|
||||||
|
|
||||||
|
Lots of people want to do this... This is a simple form which accepts a file upload and emails it.
|
||||||
|
|
||||||
|
## [send_multiple_file_upload.phps](send_multiple_file_upload.phps)
|
||||||
|
|
||||||
|
A slightly more complex form that allows uploading multiple files at once and sends all of them as attachments to an email.
|
||||||
|
|
||||||
|
## [sendmail.phps](sendmail.phps)
|
||||||
|
|
||||||
|
A simple example using sendmail. Sendmail is a program (usually found on Linux/BSD, OS X and other UNIX-alikes) that can be used to submit messages to a local mail server without a lengthy SMTP conversation. It's probably the fastest sending mechanism, but lacks some error reporting features. There are sendmail emulators for most popular mail servers including postfix, qmail, exim etc.
|
||||||
|
|
||||||
|
## [gmail.phps](gmail.phps)
|
||||||
|
|
||||||
|
Submitting email via Google's Gmail service is a popular use of PHPMailer. It's much the same as normal SMTP sending, just with some specific settings, namely using TLS encryption, authentication is enabled, and it connects to the SMTP submission port 587 on the smtp.gmail.com host. This example does all that.
|
||||||
|
|
||||||
|
## [gmail_xoauth.phps](gmail_xoauth.phps)
|
||||||
|
|
||||||
|
Gmail now likes you to use XOAUTH2 for SMTP authentication. This is extremely laborious to set up, but once it's done you can use it repeatedly and will no longer need Gmail's ineptly-named "Allow less secure apps" setting enabled. [Read the guide in the wiki](https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2) for how to set it up.
|
||||||
|
|
||||||
|
## [pop_before_smtp.phps](pop_before_smtp.phps)
|
||||||
|
|
||||||
|
Back in the stone age, before effective SMTP authentication mechanisms were available, it was common for ISPs to use POP-before-SMTP authentication. As it implies, you authenticate using the POP3 protocol (an older protocol now mostly replaced by the far superior IMAP), and then the SMTP server will allow send access from your IP address for a short while, usually 5-15 minutes. PHPMailer includes a basic POP3 protocol client with just enough functionality to carry out this sequence - it's just like a normal SMTP conversation (without authentication), but connects via POP3 first.
|
||||||
|
|
||||||
|
## [mailing_list.phps](mailing_list.phps)
|
||||||
|
|
||||||
|
This is a somewhat naïve, but reasonably efficient example of sending similar emails to a list of different addresses. It sets up a PHPMailer instance using SMTP, then connects to a MySQL database to retrieve a list of recipients. The code loops over this list, sending email to each person using their info and marks them as sent in the database. It makes use of SMTP keepalive which saves reconnecting and re-authenticating between each message.
|
||||||
|
|
||||||
|
## [ssl_options.phps](ssl_options.phps)
|
||||||
|
|
||||||
|
PHP 5.6 introduced SSL certificate verification by default, and this applies to mail servers exactly as it does to web servers. Unfortunately, SSL misconfiguration in mail servers is quite common, so this caused a common problem: those that were previously using servers with bad configs suddenly found they stopped working when they upgraded PHP. PHPMailer provides a mechanism to disable SSL certificate verification as a workaround and this example shows how to do it. Bear in mind that this is **not** a good approach - the right way is to fix your mail server config!
|
||||||
|
|
||||||
|
## [smime_signed_mail.phps](smime_signed_mail.phps)
|
||||||
|
|
||||||
|
An example of how to sign messages using [S/MIME](https://en.wikipedia.org/wiki/S/MIME), ensuring that your data can't be tampered with in transit, and proves to recipients that it was you that sent it.
|
||||||
|
|
||||||
|
* * *
|
||||||
|
|
||||||
|
## [smtp_check.phps](smtp_check.phps)
|
||||||
|
|
||||||
|
This is an example showing how to use the SMTP class by itself (without PHPMailer) to check an SMTP connection.
|
||||||
|
|
||||||
|
## [smtp_low_memory.phps](smtp_low_memory.phps)
|
||||||
|
|
||||||
|
This demonstrates how to extend the SMTP class and make PHPMailer use it. In this case it's an effort to make the SMTP class use less memory when sending large attachments.
|
||||||
|
|
||||||
|
* * *
|
126
php/PHP/fichier/php/PHP/PHPMailer/examples/azure_xoauth2.phps
Normal file
126
php/PHP/fichier/php/PHP/PHPMailer/examples/azure_xoauth2.phps
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to send via Microsoft Outlook's servers using XOAUTH2 authentication
|
||||||
|
* using the league/oauth2-client to provide the OAuth2 token.
|
||||||
|
* To use a different OAuth2 library create a wrapper class that implements OAuthTokenProvider and
|
||||||
|
* pass that wrapper class to PHPMailer::setOAuth().
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\OAuth;
|
||||||
|
//Alias the League Google OAuth2 provider class
|
||||||
|
use Greew\OAuth2\Client\Provider\Azure;
|
||||||
|
|
||||||
|
//SMTP needs accurate times, and the PHP time zone MUST be set
|
||||||
|
//This should be done in your php.ini, but this is how to do it if you don't have access to that
|
||||||
|
date_default_timezone_set('Etc/UTC');
|
||||||
|
|
||||||
|
//Load dependencies from composer
|
||||||
|
//If this causes an error, run 'composer install'
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
|
//Tell PHPMailer to use SMTP
|
||||||
|
$mail->isSMTP();
|
||||||
|
|
||||||
|
//Enable SMTP debugging
|
||||||
|
//SMTP::DEBUG_OFF = off (for production use)
|
||||||
|
//SMTP::DEBUG_CLIENT = client messages
|
||||||
|
//SMTP::DEBUG_SERVER = client and server messages
|
||||||
|
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||||
|
|
||||||
|
//Set the hostname of the mail server
|
||||||
|
$mail->Host = 'smtp.office365.com';
|
||||||
|
|
||||||
|
//Set the SMTP port number:
|
||||||
|
// - 465 for SMTP with implicit TLS, a.k.a. RFC8314 SMTPS or
|
||||||
|
// - 587 for SMTP+STARTTLS
|
||||||
|
$mail->Port = 587;
|
||||||
|
|
||||||
|
//Set the encryption mechanism to use:
|
||||||
|
// - SMTPS (implicit TLS on port 465) or
|
||||||
|
// - STARTTLS (explicit TLS on port 587)
|
||||||
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||||
|
|
||||||
|
//Whether to use SMTP authentication
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
|
|
||||||
|
//Set AuthType to use XOAUTH2
|
||||||
|
$mail->AuthType = 'XOAUTH2';
|
||||||
|
|
||||||
|
//Start Option 1: Use league/oauth2-client as OAuth2 token provider
|
||||||
|
//Fill in authentication details here
|
||||||
|
//Either the microsoft account owner, or the user that gave consent
|
||||||
|
$email = 'someone@somemicrosoftaccount.com';
|
||||||
|
$clientId = 'RANDOMCHARS-----duv1n2TS';
|
||||||
|
$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
|
||||||
|
$tenantId = 'RANDOMCHARS-----HSFTAOIlagss';
|
||||||
|
|
||||||
|
//Obtained by configuring and running get_oauth_token.php
|
||||||
|
//after setting up an app in Google Developer Console.
|
||||||
|
$refreshToken = 'RANDOMCHARS-----DWxgOvPT003r-yFUV49TQYag7_Aod7y0';
|
||||||
|
|
||||||
|
//Create a new OAuth2 provider instance
|
||||||
|
$provider = new Azure(
|
||||||
|
[
|
||||||
|
'clientId' => $clientId,
|
||||||
|
'clientSecret' => $clientSecret,
|
||||||
|
'tenantId' => $tenantId,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//Pass the OAuth provider instance to PHPMailer
|
||||||
|
$mail->setOAuth(
|
||||||
|
new OAuth(
|
||||||
|
[
|
||||||
|
'provider' => $provider,
|
||||||
|
'clientId' => $clientId,
|
||||||
|
'clientSecret' => $clientSecret,
|
||||||
|
'refreshToken' => $refreshToken,
|
||||||
|
'userName' => $email,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
//End Option 1
|
||||||
|
|
||||||
|
//Option 2: Another OAuth library as OAuth2 token provider
|
||||||
|
//Set up the other oauth library as per its documentation
|
||||||
|
//Then create the wrapper class that implementations OAuthTokenProvider
|
||||||
|
$oauthTokenProvider = new MyOAuthTokenProvider(/* Email, ClientId, ClientSecret, etc. */);
|
||||||
|
|
||||||
|
//Pass the implementation of OAuthTokenProvider to PHPMailer
|
||||||
|
$mail->setOAuth($oauthTokenProvider);
|
||||||
|
//End Option 2
|
||||||
|
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
//For Outlook, this generally needs to be the same as the user you logged in as
|
||||||
|
$mail->setFrom($email, 'First Last');
|
||||||
|
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('someone@someserver.com', 'John Doe');
|
||||||
|
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer Outlook XOAUTH2 SMTP test';
|
||||||
|
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//convert HTML into a basic plain-text alternative body
|
||||||
|
$mail->CharSet = PHPMailer::CHARSET_UTF8;
|
||||||
|
$mail->msgHTML(file_get_contents('contentsutf8.html'), __DIR__);
|
||||||
|
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
|
||||||
|
//Attach an image file
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
|
||||||
|
//send the message, check for errors
|
||||||
|
if (!$mail->send()) {
|
||||||
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
echo 'Message sent!';
|
||||||
|
}
|
76
php/PHP/fichier/php/PHP/PHPMailer/examples/callback.phps
Normal file
76
php/PHP/fichier/php/PHP/PHPMailer/examples/callback.phps
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to use a callback function from PHPMailer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example PHPMailer callback function.
|
||||||
|
* This is a global function, but you can also pass a closure (or any other callable)
|
||||||
|
* to the `action_function` property.
|
||||||
|
*
|
||||||
|
* @param bool $result result of the send action
|
||||||
|
* @param array $to email address of the recipient
|
||||||
|
* @param array $cc cc email addresses
|
||||||
|
* @param array $bcc bcc email addresses
|
||||||
|
* @param string $subject the subject
|
||||||
|
* @param string $body the email body
|
||||||
|
*/
|
||||||
|
function callbackAction($result, $to, $cc, $bcc, $subject, $body)
|
||||||
|
{
|
||||||
|
echo "Message subject: \"$subject\"\n";
|
||||||
|
foreach ($to as $address) {
|
||||||
|
echo "Message to {$address[1]} <{$address[0]}>\n";
|
||||||
|
}
|
||||||
|
foreach ($cc as $address) {
|
||||||
|
echo "Message CC to {$address[1]} <{$address[0]}>\n";
|
||||||
|
}
|
||||||
|
foreach ($bcc as $toaddress) {
|
||||||
|
echo "Message BCC to {$toaddress[1]} <{$toaddress[0]}>\n";
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
echo "Message sent successfully\n";
|
||||||
|
} else {
|
||||||
|
echo "Message send failed\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once '../vendor/autoload.php';
|
||||||
|
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mail->isMail();
|
||||||
|
$mail->setFrom('you@example.com', 'Your Name');
|
||||||
|
$mail->addAddress('jane@example.com', 'Jane Doe');
|
||||||
|
$mail->addCC('john@example.com', 'John Doe');
|
||||||
|
$mail->Subject = 'PHPMailer Test Subject';
|
||||||
|
$mail->msgHTML(file_get_contents('../examples/contents.html'));
|
||||||
|
//Optional - msgHTML will create an alternate automatically
|
||||||
|
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
$mail->action_function = 'callbackAction';
|
||||||
|
$mail->send();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->errorMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Alternative approach using a closure
|
||||||
|
try {
|
||||||
|
$mail->action_function = static function ($result, $to, $cc, $bcc, $subject, $body) {
|
||||||
|
if ($result) {
|
||||||
|
echo "Message sent successfully\n";
|
||||||
|
} else {
|
||||||
|
echo "Message send failed\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$mail->send();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->errorMessage();
|
||||||
|
}
|
146
php/PHP/fichier/php/PHP/PHPMailer/examples/contactform-ajax.phps
Normal file
146
php/PHP/fichier/php/PHP/PHPMailer/examples/contactform-ajax.phps
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to handle a simple contact form safely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
//Don't run this unless we're handling a form submission
|
||||||
|
if (array_key_exists('email', $_POST)) {
|
||||||
|
date_default_timezone_set('Etc/UTC');
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
$isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
||||||
|
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
//Send using SMTP to localhost (faster and safer than using mail()) – requires a local mail server
|
||||||
|
//See other examples for how to use a remote server such as gmail
|
||||||
|
$mail->isSMTP();
|
||||||
|
$mail->Host = 'localhost';
|
||||||
|
$mail->Port = 25;
|
||||||
|
|
||||||
|
//Use a fixed address in your own domain as the from address
|
||||||
|
//**DO NOT** use the submitter's address here as it will be forgery
|
||||||
|
//and will cause your messages to fail SPF checks
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
//Choose who the message should be sent to
|
||||||
|
//You don't have to use a <select> like in this example, you can simply use a fixed address
|
||||||
|
//the important thing is *not* to trust an email address submitted from the form directly,
|
||||||
|
//as an attacker can substitute their own and try to use your form to send spam
|
||||||
|
$addresses = [
|
||||||
|
'sales' => 'sales@example.com',
|
||||||
|
'support' => 'support@example.com',
|
||||||
|
'accounts' => 'accounts@example.com',
|
||||||
|
];
|
||||||
|
//Validate address selection before trying to use it
|
||||||
|
if (array_key_exists('dept', $_POST) && array_key_exists($_POST['dept'], $addresses)) {
|
||||||
|
$mail->addAddress($addresses[$_POST['dept']]);
|
||||||
|
} else {
|
||||||
|
//Fall back to a fixed address if dept selection is invalid or missing
|
||||||
|
$mail->addAddress('support@example.com');
|
||||||
|
}
|
||||||
|
//Put the submitter's address in a reply-to header
|
||||||
|
//This will fail if the address provided is invalid,
|
||||||
|
//in which case we should ignore the whole request
|
||||||
|
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
|
||||||
|
$mail->Subject = 'PHPMailer contact form';
|
||||||
|
//Keep it simple - don't use HTML
|
||||||
|
$mail->isHTML(false);
|
||||||
|
//Build a simple message body
|
||||||
|
$mail->Body = <<<EOT
|
||||||
|
Email: {$_POST['email']}
|
||||||
|
Name: {$_POST['name']}
|
||||||
|
Message: {$_POST['message']}
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
//Send the message, check for errors
|
||||||
|
if (!$mail->send()) {
|
||||||
|
//The reason for failing to send will be in $mail->ErrorInfo
|
||||||
|
//but it's unsafe to display errors directly to users - process the error, log it on your server.
|
||||||
|
if ($isAjax) {
|
||||||
|
http_response_code(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"status" => false,
|
||||||
|
"message" => 'Sorry, something went wrong. Please try again later.'
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$response = [
|
||||||
|
"status" => true,
|
||||||
|
"message" => 'Message sent! Thanks for contacting us.'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response = [
|
||||||
|
"status" => false,
|
||||||
|
"message" => 'Invalid email address, message ignored.'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isAjax) {
|
||||||
|
header('Content-type:application/json;charset=utf-8');
|
||||||
|
echo json_encode($response);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Contact form</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Contact us</h1>
|
||||||
|
<h2 id="status-message"><?php if (isset($response)) {
|
||||||
|
echo $response['message'];
|
||||||
|
}?></h2>
|
||||||
|
<form method="POST" id="contact-form">
|
||||||
|
<label for="name">Name: <input type="text" name="name" id="name"></label><br>
|
||||||
|
<label for="email">Email address: <input type="email" name="email" id="email"></label><br>
|
||||||
|
<label for="message">Message: <textarea name="message" id="message" rows="8" cols="20"></textarea></label><br>
|
||||||
|
<label for="dept">Send query to department:</label>
|
||||||
|
<select name="dept" id="dept">
|
||||||
|
<option value="sales">Sales</option>
|
||||||
|
<option value="support" selected>Technical support</option>
|
||||||
|
<option value="accounts">Accounts</option>
|
||||||
|
</select><br>
|
||||||
|
<input type="submit" value="Send">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script type="application/javascript">
|
||||||
|
const form = document.getElementById("contact-form")
|
||||||
|
|
||||||
|
function email(data) {
|
||||||
|
const message = document.getElementById("status-message")
|
||||||
|
fetch("", {
|
||||||
|
method: "POST",
|
||||||
|
body: data,
|
||||||
|
headers: {
|
||||||
|
'X-Requested-With' : 'XMLHttpRequest'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(response => {message.innerHTML = response.message})
|
||||||
|
.catch(error => {
|
||||||
|
error.json().then(response => {
|
||||||
|
message.innerHTML = response.message
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const submitEvent = form.addEventListener("submit", (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const formData = new FormData(form);
|
||||||
|
|
||||||
|
email(formData);
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
95
php/PHP/fichier/php/PHP/PHPMailer/examples/contactform.phps
Normal file
95
php/PHP/fichier/php/PHP/PHPMailer/examples/contactform.phps
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to handle a simple contact form safely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
$msg = '';
|
||||||
|
//Don't run this unless we're handling a form submission
|
||||||
|
if (array_key_exists('email', $_POST)) {
|
||||||
|
date_default_timezone_set('Etc/UTC');
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
//Send using SMTP to localhost (faster and safer than using mail()) – requires a local mail server
|
||||||
|
//See other examples for how to use a remote server such as gmail
|
||||||
|
$mail->isSMTP();
|
||||||
|
$mail->Host = 'localhost';
|
||||||
|
$mail->Port = 25;
|
||||||
|
|
||||||
|
//Use a fixed address in your own domain as the from address
|
||||||
|
//**DO NOT** use the submitter's address here as it will be forgery
|
||||||
|
//and will cause your messages to fail SPF checks
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
//Choose who the message should be sent to
|
||||||
|
//You don't have to use a <select> like in this example, you can simply use a fixed address
|
||||||
|
//the important thing is *not* to trust an email address submitted from the form directly,
|
||||||
|
//as an attacker can substitute their own and try to use your form to send spam
|
||||||
|
$addresses = [
|
||||||
|
'sales' => 'sales@example.com',
|
||||||
|
'support' => 'support@example.com',
|
||||||
|
'accounts' => 'accounts@example.com',
|
||||||
|
];
|
||||||
|
//Validate address selection before trying to use it
|
||||||
|
if (array_key_exists('dept', $_POST) && array_key_exists($_POST['dept'], $addresses)) {
|
||||||
|
$mail->addAddress($addresses[$_POST['dept']]);
|
||||||
|
} else {
|
||||||
|
//Fall back to a fixed address if dept selection is invalid or missing
|
||||||
|
$mail->addAddress('support@example.com');
|
||||||
|
}
|
||||||
|
//Put the submitter's address in a reply-to header
|
||||||
|
//This will fail if the address provided is invalid,
|
||||||
|
//in which case we should ignore the whole request
|
||||||
|
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
|
||||||
|
$mail->Subject = 'PHPMailer contact form';
|
||||||
|
//Keep it simple - don't use HTML
|
||||||
|
$mail->isHTML(false);
|
||||||
|
//Build a simple message body
|
||||||
|
$mail->Body = <<<EOT
|
||||||
|
Email: {$_POST['email']}
|
||||||
|
Name: {$_POST['name']}
|
||||||
|
Message: {$_POST['message']}
|
||||||
|
EOT;
|
||||||
|
//Send the message, check for errors
|
||||||
|
if (!$mail->send()) {
|
||||||
|
//The reason for failing to send will be in $mail->ErrorInfo
|
||||||
|
//but it's unsafe to display errors directly to users - process the error, log it on your server.
|
||||||
|
$msg = 'Sorry, something went wrong. Please try again later.';
|
||||||
|
} else {
|
||||||
|
$msg = 'Message sent! Thanks for contacting us.';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$msg = 'Invalid email address, message ignored.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Contact form</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Contact us</h1>
|
||||||
|
<?php if (!empty($msg)) {
|
||||||
|
echo "<h2>$msg</h2>";
|
||||||
|
} ?>
|
||||||
|
<form method="POST">
|
||||||
|
<label for="name">Name: <input type="text" name="name" id="name"></label><br>
|
||||||
|
<label for="email">Email address: <input type="email" name="email" id="email"></label><br>
|
||||||
|
<label for="message">Message: <textarea name="message" id="message" rows="8" cols="20"></textarea></label><br>
|
||||||
|
<label for="dept">Send query to department:</label>
|
||||||
|
<select name="dept" id="dept">
|
||||||
|
<option value="sales">Sales</option>
|
||||||
|
<option value="support" selected>Technical support</option>
|
||||||
|
<option value="accounts">Accounts</option>
|
||||||
|
</select><br>
|
||||||
|
<input type="submit" value="Send">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
17
php/PHP/fichier/php/PHP/PHPMailer/examples/contents.html
Normal file
17
php/PHP/fichier/php/PHP/PHPMailer/examples/contents.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||||
|
<title>PHPMailer Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
|
||||||
|
<h1>This is a test of PHPMailer.</h1>
|
||||||
|
<div align="center">
|
||||||
|
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
|
||||||
|
</div>
|
||||||
|
<p>This example uses <strong>HTML</strong>.</p>
|
||||||
|
<p>ISO-8859-1 text: éèîüçÅñæß</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
23
php/PHP/fichier/php/PHP/PHPMailer/examples/contentsutf8.html
Normal file
23
php/PHP/fichier/php/PHP/PHPMailer/examples/contentsutf8.html
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>PHPMailer Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
|
||||||
|
<h1>This is a test of PHPMailer.</h1>
|
||||||
|
<div align="center">
|
||||||
|
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
|
||||||
|
</div>
|
||||||
|
<p>This example uses <strong>HTML</strong> with the UTF-8 unicode charset.</p>
|
||||||
|
<p>Chinese text: 郵件內容為空</p>
|
||||||
|
<p>Russian text: Пустое тело сообщения</p>
|
||||||
|
<p>Armenian text: Հաղորդագրությունը դատարկ է</p>
|
||||||
|
<p>Czech text: Prázdné tělo zprávy</p>
|
||||||
|
<p>Emoji: <span style="font-size: 48px">😂 🦄 💥 📤 📧</span></p>
|
||||||
|
<p>Image data URL (base64)<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="#"></p>
|
||||||
|
<p>Image data URL (URL-encoded)<img src="data:image/gif,GIF89a%01%00%01%00%00%00%00%21%F9%04%01%0A%00%01%00%2C%00%00%00%00%01%00%01%00%00%02%02L%01%00%3B" alt="#"></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
40
php/PHP/fichier/php/PHP/PHPMailer/examples/exceptions.phps
Normal file
40
php/PHP/fichier/php/PHP/PHPMailer/examples/exceptions.phps
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to make use of PHPMailer's exceptions for error handling.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
//Passing true to the constructor enables the use of exceptions for error handling
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
try {
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
//Set an alternative reply-to address
|
||||||
|
$mail->addReplyTo('replyto@example.com', 'First Last');
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer Exceptions test';
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//and convert the HTML into a basic plain-text alternative body
|
||||||
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
//Attach an image file
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
//send the message
|
||||||
|
//Note that we don't need check the response from this because it will throw an exception if it has trouble
|
||||||
|
$mail->send();
|
||||||
|
echo 'Message sent!';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->errorMessage(); //Pretty error messages from PHPMailer
|
||||||
|
} catch (\Exception $e) { //The leading slash means the Global PHP Exception class will be caught
|
||||||
|
echo $e->getMessage(); //Boring error messages from anything else!
|
||||||
|
}
|
72
php/PHP/fichier/php/PHP/PHPMailer/examples/extending.phps
Normal file
72
php/PHP/fichier/php/PHP/PHPMailer/examples/extending.phps
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to extend PHPMailer to simplify your coding.
|
||||||
|
* If PHPMailer doesn't do something the way you want it to, or your code
|
||||||
|
* contains too much boilerplate, don't edit the library files,
|
||||||
|
* create a subclass instead and customise that.
|
||||||
|
* That way all your changes will be retained when PHPMailer is updated.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use PHPMailer as a base class and extend it
|
||||||
|
*/
|
||||||
|
class MyPHPMailer extends PHPMailer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* myPHPMailer constructor.
|
||||||
|
*
|
||||||
|
* @param bool|null $exceptions
|
||||||
|
* @param string $body A default HTML message body
|
||||||
|
*/
|
||||||
|
public function __construct($exceptions, $body = '')
|
||||||
|
{
|
||||||
|
//Don't forget to do this or other things may not be set correctly!
|
||||||
|
parent::__construct($exceptions);
|
||||||
|
//Set a default 'From' address
|
||||||
|
$this->setFrom('joe@example.com', 'Joe User');
|
||||||
|
//Send via SMTP
|
||||||
|
$this->isSMTP();
|
||||||
|
//Equivalent to setting `Host`, `Port` and `SMTPSecure` all at once
|
||||||
|
$this->Host = 'tls://smtp.example.com:587';
|
||||||
|
//Set an HTML and plain-text body, import relative image references
|
||||||
|
$this->msgHTML($body, './images/');
|
||||||
|
//Show debug output
|
||||||
|
$this->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||||
|
//Inject a new debug output handler
|
||||||
|
$this->Debugoutput = static function ($str, $level) {
|
||||||
|
echo "Debug level $level; message: $str\n";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//Extend the send function
|
||||||
|
public function send()
|
||||||
|
{
|
||||||
|
$this->Subject = '[Yay for me!] ' . $this->Subject;
|
||||||
|
$r = parent::send();
|
||||||
|
echo 'I sent a message with subject ' . $this->Subject;
|
||||||
|
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Now creating and sending a message becomes simpler when you use this class in your app code
|
||||||
|
try {
|
||||||
|
//Instantiate your new class, making use of the new `$body` parameter
|
||||||
|
$mail = new myPHPMailer(true, '<strong>This is the message body</strong>');
|
||||||
|
//Now you only need to set things that are different from the defaults you defined
|
||||||
|
$mail->addAddress('jane@example.com', 'Jane User');
|
||||||
|
$mail->Subject = 'Here is the subject';
|
||||||
|
$mail->addAttachment(__FILE__, 'myPHPMailer.php');
|
||||||
|
$mail->send(); //No need to check for errors - the exception handler will do it
|
||||||
|
} catch (Exception $e) {
|
||||||
|
//Note that this is catching the PHPMailer Exception class, not the global \Exception type!
|
||||||
|
echo 'Caught a ' . get_class($e) . ': ' . $e->getMessage();
|
||||||
|
}
|
108
php/PHP/fichier/php/PHP/PHPMailer/examples/gmail.phps
Normal file
108
php/PHP/fichier/php/PHP/PHPMailer/examples/gmail.phps
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows settings to use when sending via Google's Gmail servers.
|
||||||
|
* This uses traditional id & password authentication - look at the gmail_xoauth.phps
|
||||||
|
* example to see how to use XOAUTH2.
|
||||||
|
* The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
|
//Tell PHPMailer to use SMTP
|
||||||
|
$mail->isSMTP();
|
||||||
|
|
||||||
|
//Enable SMTP debugging
|
||||||
|
//SMTP::DEBUG_OFF = off (for production use)
|
||||||
|
//SMTP::DEBUG_CLIENT = client messages
|
||||||
|
//SMTP::DEBUG_SERVER = client and server messages
|
||||||
|
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||||
|
|
||||||
|
//Set the hostname of the mail server
|
||||||
|
$mail->Host = 'smtp.gmail.com';
|
||||||
|
//Use `$mail->Host = gethostbyname('smtp.gmail.com');`
|
||||||
|
//if your network does not support SMTP over IPv6,
|
||||||
|
//though this may cause issues with TLS
|
||||||
|
|
||||||
|
//Set the SMTP port number:
|
||||||
|
// - 465 for SMTP with implicit TLS, a.k.a. RFC8314 SMTPS or
|
||||||
|
// - 587 for SMTP+STARTTLS
|
||||||
|
$mail->Port = 465;
|
||||||
|
|
||||||
|
//Set the encryption mechanism to use:
|
||||||
|
// - SMTPS (implicit TLS on port 465) or
|
||||||
|
// - STARTTLS (explicit TLS on port 587)
|
||||||
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||||
|
|
||||||
|
//Whether to use SMTP authentication
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
|
|
||||||
|
//Username to use for SMTP authentication - use full email address for gmail
|
||||||
|
$mail->Username = 'username@gmail.com';
|
||||||
|
|
||||||
|
//Password to use for SMTP authentication
|
||||||
|
$mail->Password = 'yourpassword';
|
||||||
|
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
//Note that with gmail you can only use your account address (same as `Username`)
|
||||||
|
//or predefined aliases that you have configured within your account.
|
||||||
|
//Do not use user-submitted addresses in here
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
|
||||||
|
//Set an alternative reply-to address
|
||||||
|
//This is a good place to put user-submitted addresses
|
||||||
|
$mail->addReplyTo('replyto@example.com', 'First Last');
|
||||||
|
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer GMail SMTP test';
|
||||||
|
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//convert HTML into a basic plain-text alternative body
|
||||||
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
||||||
|
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
|
||||||
|
//Attach an image file
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
|
||||||
|
//send the message, check for errors
|
||||||
|
if (!$mail->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;
|
||||||
|
}
|
121
php/PHP/fichier/php/PHP/PHPMailer/examples/gmail_xoauth.phps
Normal file
121
php/PHP/fichier/php/PHP/PHPMailer/examples/gmail_xoauth.phps
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to send via Google's Gmail servers using XOAUTH2 authentication
|
||||||
|
* using the league/oauth2-client to provide the OAuth2 token.
|
||||||
|
* To use a different OAuth2 library create a wrapper class that implements OAuthTokenProvider and
|
||||||
|
* pass that wrapper class to PHPMailer::setOAuth().
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\OAuth;
|
||||||
|
//Alias the League Google OAuth2 provider class
|
||||||
|
use League\OAuth2\Client\Provider\Google;
|
||||||
|
|
||||||
|
//SMTP needs accurate times, and the PHP time zone MUST be set
|
||||||
|
//This should be done in your php.ini, but this is how to do it if you don't have access to that
|
||||||
|
date_default_timezone_set('Etc/UTC');
|
||||||
|
|
||||||
|
//Load dependencies from composer
|
||||||
|
//If this causes an error, run 'composer install'
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
|
//Tell PHPMailer to use SMTP
|
||||||
|
$mail->isSMTP();
|
||||||
|
|
||||||
|
//Enable SMTP debugging
|
||||||
|
//SMTP::DEBUG_OFF = off (for production use)
|
||||||
|
//SMTP::DEBUG_CLIENT = client messages
|
||||||
|
//SMTP::DEBUG_SERVER = client and server messages
|
||||||
|
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||||
|
|
||||||
|
//Set the hostname of the mail server
|
||||||
|
$mail->Host = 'smtp.gmail.com';
|
||||||
|
|
||||||
|
//Set the SMTP port number:
|
||||||
|
// - 465 for SMTP with implicit TLS, a.k.a. RFC8314 SMTPS or
|
||||||
|
// - 587 for SMTP+STARTTLS
|
||||||
|
$mail->Port = 465;
|
||||||
|
|
||||||
|
//Set the encryption mechanism to use:
|
||||||
|
// - SMTPS (implicit TLS on port 465) or
|
||||||
|
// - STARTTLS (explicit TLS on port 587)
|
||||||
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||||
|
|
||||||
|
//Whether to use SMTP authentication
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
|
|
||||||
|
//Set AuthType to use XOAUTH2
|
||||||
|
$mail->AuthType = 'XOAUTH2';
|
||||||
|
|
||||||
|
//Start Option 1: Use league/oauth2-client as OAuth2 token provider
|
||||||
|
//Fill in authentication details here
|
||||||
|
//Either the gmail account owner, or the user that gave consent
|
||||||
|
$email = 'someone@gmail.com';
|
||||||
|
$clientId = 'RANDOMCHARS-----duv1n2.apps.googleusercontent.com';
|
||||||
|
$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
|
||||||
|
|
||||||
|
//Obtained by configuring and running get_oauth_token.php
|
||||||
|
//after setting up an app in Google Developer Console.
|
||||||
|
$refreshToken = 'RANDOMCHARS-----DWxgOvPT003r-yFUV49TQYag7_Aod7y0';
|
||||||
|
|
||||||
|
//Create a new OAuth2 provider instance
|
||||||
|
$provider = new Google(
|
||||||
|
[
|
||||||
|
'clientId' => $clientId,
|
||||||
|
'clientSecret' => $clientSecret,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//Pass the OAuth provider instance to PHPMailer
|
||||||
|
$mail->setOAuth(
|
||||||
|
new OAuth(
|
||||||
|
[
|
||||||
|
'provider' => $provider,
|
||||||
|
'clientId' => $clientId,
|
||||||
|
'clientSecret' => $clientSecret,
|
||||||
|
'refreshToken' => $refreshToken,
|
||||||
|
'userName' => $email,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
//End Option 1
|
||||||
|
|
||||||
|
//Option 2: Another OAuth library as OAuth2 token provider
|
||||||
|
//Set up the other oauth library as per its documentation
|
||||||
|
//Then create the wrapper class that implements OAuthTokenProvider
|
||||||
|
$oauthTokenProvider = new MyOAuthTokenProvider(/* Email, ClientId, ClientSecret, etc. */);
|
||||||
|
|
||||||
|
//Pass the implementation of OAuthTokenProvider to PHPMailer
|
||||||
|
$mail->setOAuth($oauthTokenProvider);
|
||||||
|
//End Option 2
|
||||||
|
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
//For gmail, this generally needs to be the same as the user you logged in as
|
||||||
|
$mail->setFrom($email, 'First Last');
|
||||||
|
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('someone@gmail.com', 'John Doe');
|
||||||
|
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer GMail XOAUTH2 SMTP test';
|
||||||
|
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//convert HTML into a basic plain-text alternative body
|
||||||
|
$mail->CharSet = PHPMailer::CHARSET_UTF8;
|
||||||
|
$mail->msgHTML(file_get_contents('contentsutf8.html'), __DIR__);
|
||||||
|
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
|
||||||
|
//send the message, check for errors
|
||||||
|
if (!$mail->send()) {
|
||||||
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
echo 'Message sent!';
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 53 KiB |
BIN
php/PHP/fichier/php/PHP/PHPMailer/examples/images/phpmailer.png
Normal file
BIN
php/PHP/fichier/php/PHP/PHPMailer/examples/images/phpmailer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
35
php/PHP/fichier/php/PHP/PHPMailer/examples/mail.phps
Normal file
35
php/PHP/fichier/php/PHP/PHPMailer/examples/mail.phps
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows sending a message using PHP's mail() function.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import the PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
//Set an alternative reply-to address
|
||||||
|
$mail->addReplyTo('replyto@example.com', 'First Last');
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer mail() test';
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//convert HTML into a basic plain-text alternative body
|
||||||
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
//Attach an image file
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
|
||||||
|
//send the message, check for errors
|
||||||
|
if (!$mail->send()) {
|
||||||
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
echo 'Message sent!';
|
||||||
|
}
|
86
php/PHP/fichier/php/PHP/PHPMailer/examples/mailing_list.phps
Normal file
86
php/PHP/fichier/php/PHP/PHPMailer/examples/mailing_list.phps
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to send a message to a whole list of recipients efficiently.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import the PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
error_reporting(E_STRICT | E_ALL);
|
||||||
|
|
||||||
|
date_default_timezone_set('Etc/UTC');
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Passing `true` enables PHPMailer exceptions
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
|
||||||
|
$body = file_get_contents('contents.html');
|
||||||
|
|
||||||
|
$mail->isSMTP();
|
||||||
|
$mail->Host = 'smtp.example.com';
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
|
$mail->SMTPKeepAlive = true; //SMTP connection will not close after each email sent, reduces SMTP overhead
|
||||||
|
$mail->Port = 25;
|
||||||
|
$mail->Username = 'yourname@example.com';
|
||||||
|
$mail->Password = 'yourpassword';
|
||||||
|
$mail->setFrom('list@example.com', 'List manager');
|
||||||
|
$mail->addReplyTo('list@example.com', 'List manager');
|
||||||
|
$mail->addCustomHeader(
|
||||||
|
'List-Unsubscribe',
|
||||||
|
'<mailto:unsubscribes@example.com>, <https://www.example.com/unsubscribe.php>'
|
||||||
|
);
|
||||||
|
$mail->Subject = 'PHPMailer Simple database mailing list test';
|
||||||
|
|
||||||
|
//Same body for all messages, so set this before the sending loop
|
||||||
|
//If you generate a different body for each recipient (e.g. you're using a templating system),
|
||||||
|
//set it inside the loop
|
||||||
|
$mail->msgHTML($body);
|
||||||
|
//msgHTML also sets AltBody, but if you want a custom one, set it afterwards
|
||||||
|
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
|
||||||
|
|
||||||
|
//Connect to the database and select the recipients from your mailing list that have not yet been sent to
|
||||||
|
//You'll need to alter this to match your database
|
||||||
|
$mysql = mysqli_connect('localhost', 'username', 'password');
|
||||||
|
mysqli_select_db($mysql, 'mydb');
|
||||||
|
$result = mysqli_query($mysql, 'SELECT full_name, email, photo FROM mailinglist WHERE sent = FALSE');
|
||||||
|
|
||||||
|
foreach ($result as $row) {
|
||||||
|
try {
|
||||||
|
$mail->addAddress($row['email'], $row['full_name']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo 'Invalid address skipped: ' . htmlspecialchars($row['email']) . '<br>';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!empty($row['photo'])) {
|
||||||
|
//Assumes the image data is stored in the DB
|
||||||
|
$mail->addStringAttachment($row['photo'], 'YourPhoto.jpg');
|
||||||
|
}
|
||||||
|
$mail->replaceCustomHeader(
|
||||||
|
'List-Unsubscribe',
|
||||||
|
'<mailto:unsubscribes@example.com>, <https://www.example.com/unsubscribe.php?email=' .
|
||||||
|
rawurlencode($row['email']) . '>'
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mail->send();
|
||||||
|
echo 'Message sent to :' . htmlspecialchars($row['full_name']) . ' (' .
|
||||||
|
htmlspecialchars($row['email']) . ')<br>';
|
||||||
|
//Mark it as sent in the DB
|
||||||
|
mysqli_query(
|
||||||
|
$mysql,
|
||||||
|
"UPDATE mailinglist SET sent = TRUE WHERE email = '" .
|
||||||
|
mysqli_real_escape_string($mysql, $row['email']) . "'"
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo 'Mailer Error (' . htmlspecialchars($row['email']) . ') ' . $mail->ErrorInfo . '<br>';
|
||||||
|
//Reset the connection to abort sending this message
|
||||||
|
//The loop will continue trying to send to the rest of the list
|
||||||
|
$mail->getSMTPInstance()->reset();
|
||||||
|
}
|
||||||
|
//Clear all addresses and attachments for the next iteration
|
||||||
|
$mail->clearAddresses();
|
||||||
|
$mail->clearAttachments();
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows how to use POP-before-SMTP for authentication.
|
||||||
|
* POP-before-SMTP is a very old technology that is hardly used any more.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import PHPMailer classes into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
use PHPMailer\PHPMailer\POP3;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Authenticate via POP3.
|
||||||
|
//After this you should be allowed to submit messages over SMTP for a few minutes.
|
||||||
|
//Only applies if your host supports POP-before-SMTP.
|
||||||
|
$pop = POP3::popBeforeSmtp('pop3.example.com', 110, 30, 'username', 'password', 1);
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
//Passing true to the constructor enables the use of exceptions for error handling
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
try {
|
||||||
|
$mail->isSMTP();
|
||||||
|
//Enable SMTP debugging
|
||||||
|
//SMTP::DEBUG_OFF = off (for production use)
|
||||||
|
//SMTP::DEBUG_CLIENT = client messages
|
||||||
|
//SMTP::DEBUG_SERVER = client and server messages
|
||||||
|
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||||
|
//Set the hostname of the mail server
|
||||||
|
$mail->Host = 'mail.example.com';
|
||||||
|
//Set the SMTP port number - likely to be 25, 465 or 587
|
||||||
|
$mail->Port = 25;
|
||||||
|
//Whether to use SMTP authentication
|
||||||
|
$mail->SMTPAuth = false;
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
//Set an alternative reply-to address
|
||||||
|
$mail->addReplyTo('replyto@example.com', 'First Last');
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer POP-before-SMTP test';
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//and convert the HTML into a basic plain-text alternative body
|
||||||
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
//Attach an image file
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
//send the message
|
||||||
|
//Note that we don't need check the response from this because it will throw an exception if it has trouble
|
||||||
|
$mail->send();
|
||||||
|
echo 'Message sent!';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->errorMessage(); //Pretty error messages from PHPMailer
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo $e->getMessage(); //Boring error messages from anything else!
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHPMailer simple file upload and send example.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import the PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
$msg = '';
|
||||||
|
if (array_key_exists('userfile', $_FILES)) {
|
||||||
|
//First handle the upload
|
||||||
|
//Don't trust provided filename - same goes for MIME types
|
||||||
|
//See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
|
||||||
|
//Extract an extension from the provided filename
|
||||||
|
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
|
||||||
|
//Define a safe location to move the uploaded file to, preserving the extension
|
||||||
|
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'])) . '.' . $ext;
|
||||||
|
|
||||||
|
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
||||||
|
//Upload handled successfully
|
||||||
|
//Now create a message
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
$mail->Subject = 'PHPMailer file sender';
|
||||||
|
$mail->Body = 'My message body';
|
||||||
|
//Attach the uploaded file
|
||||||
|
if (!$mail->addAttachment($uploadfile, 'My uploaded file')) {
|
||||||
|
$msg .= 'Failed to attach file ' . $_FILES['userfile']['name'];
|
||||||
|
}
|
||||||
|
if (!$mail->send()) {
|
||||||
|
$msg .= 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
$msg .= 'Message sent!';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$msg .= 'Failed to move file to ' . $uploadfile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>PHPMailer Upload</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php if (empty($msg)) { ?>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="MAX_FILE_SIZE" value="100000"> Send this file: <input name="userfile" type="file">
|
||||||
|
<input type="submit" value="Send File">
|
||||||
|
</form>
|
||||||
|
<?php } else {
|
||||||
|
echo htmlspecialchars($msg);
|
||||||
|
} ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHPMailer multiple files upload and send example
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import the PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
$msg = '';
|
||||||
|
if (array_key_exists('userfile', $_FILES)) {
|
||||||
|
//Create a message
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
$mail->Subject = 'PHPMailer file sender';
|
||||||
|
$mail->Body = 'My message body';
|
||||||
|
//Attach multiple files one by one
|
||||||
|
for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) {
|
||||||
|
//Extract an extension from the provided filename
|
||||||
|
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'][$ct], PATHINFO_EXTENSION);
|
||||||
|
//Define a safe location to move the uploaded file to, preserving the extension
|
||||||
|
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])) . '.' . $ext;
|
||||||
|
$filename = $_FILES['userfile']['name'][$ct];
|
||||||
|
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
|
||||||
|
if (!$mail->addAttachment($uploadfile, $filename)) {
|
||||||
|
$msg .= 'Failed to attach file ' . $filename;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$msg .= 'Failed to move file to ' . $uploadfile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$mail->send()) {
|
||||||
|
$msg .= 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
$msg .= 'Message sent!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>PHPMailer Upload</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php if (empty($msg)) { ?>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
|
||||||
|
Select one or more files:
|
||||||
|
<input name="userfile[]" type="file" multiple="multiple">
|
||||||
|
<input type="submit" value="Send Files">
|
||||||
|
</form>
|
||||||
|
<?php } else {
|
||||||
|
echo htmlspecialchars($msg);
|
||||||
|
} ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
37
php/PHP/fichier/php/PHP/PHPMailer/examples/sendmail.phps
Normal file
37
php/PHP/fichier/php/PHP/PHPMailer/examples/sendmail.phps
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This example shows sending a message using a local sendmail binary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Import the PHPMailer class into the global namespace
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
//Create a new PHPMailer instance
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
//Set PHPMailer to use the sendmail transport
|
||||||
|
$mail->isSendmail();
|
||||||
|
//Set who the message is to be sent from
|
||||||
|
$mail->setFrom('from@example.com', 'First Last');
|
||||||
|
//Set an alternative reply-to address
|
||||||
|
$mail->addReplyTo('replyto@example.com', 'First Last');
|
||||||
|
//Set who the message is to be sent to
|
||||||
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||||
|
//Set the subject line
|
||||||
|
$mail->Subject = 'PHPMailer sendmail test';
|
||||||
|
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||||||
|
//convert HTML into a basic plain-text alternative body
|
||||||
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
||||||
|
//Replace the plain text body with one created manually
|
||||||
|
$mail->AltBody = 'This is a plain-text message body';
|
||||||
|
//Attach an image file
|
||||||
|
$mail->addAttachment('images/phpmailer_mini.png');
|
||||||
|
|
||||||
|
//send the message, check for errors
|
||||||
|
if (!$mail->send()) {
|
||||||
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
} else {
|
||||||
|
echo 'Message sent!';
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user