Version 0.3.5 beta
This commit is contained in:
77
core/l/PHPMailer/examples/DKIM_gen_keys.phps
Executable file
77
core/l/PHPMailer/examples/DKIM_gen_keys.phps
Executable file
@@ -0,0 +1,77 @@
|
||||
<?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.port25.com/support/domainkeysdkim-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 Port25's DKIM tester:
|
||||
* https://www.port25.com/support/authentication-center/email-verification/
|
||||
*
|
||||
* 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';
|
||||
|
||||
//Path to your private key:
|
||||
$privatekeyfile = 'dkim_private.pem';
|
||||
//Path to your public key:
|
||||
$publickeyfile = '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;
|
||||
|
||||
//Prep 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";
|
||||
//Some DNS server don't like ; chars unless backslash-escaped
|
||||
$dnsvalue = '"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) . '" ';
|
||||
}
|
||||
echo "\n\nDNS key:\n\n" . trim($dnskey);
|
||||
echo "\n\nDNS value:\n\n" . trim($dnsvalue);
|
||||
41
core/l/PHPMailer/examples/DKIM_sign.phps
Executable file
41
core/l/PHPMailer/examples/DKIM_sign.phps
Executable file
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
|
||||
//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!";
|
||||
}
|
||||
98
core/l/PHPMailer/examples/README.md
Executable file
98
core/l/PHPMailer/examples/README.md
Executable file
@@ -0,0 +1,98 @@
|
||||
[](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:
|
||||
|
||||
* [FakeSMTP](https://github.com/Nilhcem/FakeSMTP), a Java desktop app with the ability to show an SMTP log and save messages to a folder.
|
||||
* [FakeEmail](https://github.com/isotoma/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](http://smtp4dev.codeplex.com), a dummy SMTP server for Windows.
|
||||
* [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.
|
||||
* [msglint](http://tools.ietf.org/tools/msglint/), not a mail server, the IETF's MIME structure analyser checks the formatting of your messages.
|
||||
|
||||
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!
|
||||
|
||||
## [code_generator.phps](code_generator.phps)
|
||||
|
||||
This script is a simple code generator - fill in the form and hit submit, and it will use what you entered to email you a message, and will also generate PHP code using your settings that you can copy and paste to use in your own apps.
|
||||
|
||||
## [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.
|
||||
|
||||
* * *
|
||||
75
core/l/PHPMailer/examples/callback.phps
Executable file
75
core/l/PHPMailer/examples/callback.phps
Executable file
@@ -0,0 +1,75 @@
|
||||
<?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'); // attachment
|
||||
$mail->action_function = 'callbackAction';
|
||||
$mail->send();
|
||||
} catch (Exception $e) {
|
||||
echo $e->errorMessage();
|
||||
}
|
||||
|
||||
//Alternative approach using a closure
|
||||
try {
|
||||
$mail->action_function = 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();
|
||||
}
|
||||
71
core/l/PHPMailer/examples/contactform.phps
Executable file
71
core/l/PHPMailer/examples/contactform.phps
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* This example shows how to handle a simple contact form.
|
||||
*/
|
||||
|
||||
$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 '../PHPMailerAutoload.php';
|
||||
|
||||
//Create a new PHPMailer instance
|
||||
$mail = new PHPMailer;
|
||||
//Tell PHPMailer to use SMTP - requires a local mail server
|
||||
//Faster and safer than using mail()
|
||||
$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');
|
||||
//Send the message to yourself, or whoever should receive contact for submissions
|
||||
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||
//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 you shouldn't display errors 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>
|
||||
<input type="submit" value="Send">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
17
core/l/PHPMailer/examples/contents.html
Executable file
17
core/l/PHPMailer/examples/contents.html
Executable file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<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: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
23
core/l/PHPMailer/examples/contentsutf8.html
Executable file
23
core/l/PHPMailer/examples/contentsutf8.html
Executable file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<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>
|
||||
39
core/l/PHPMailer/examples/exceptions.phps
Executable file
39
core/l/PHPMailer/examples/exceptions.phps
Executable file
@@ -0,0 +1,39 @@
|
||||
<?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!
|
||||
}
|
||||
70
core/l/PHPMailer/examples/extending.phps
Executable file
70
core/l/PHPMailer/examples/extending.phps
Executable file
@@ -0,0 +1,70 @@
|
||||
<?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\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 = 2;
|
||||
//Inject a new debug output handler
|
||||
$this->Debugoutput = 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();
|
||||
}
|
||||
98
core/l/PHPMailer/examples/gmail.phps
Executable file
98
core/l/PHPMailer/examples/gmail.phps
Executable file
@@ -0,0 +1,98 @@
|
||||
<?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;
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
//Create a new PHPMailer instance
|
||||
$mail = new PHPMailer;
|
||||
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
|
||||
//Enable SMTP debugging
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 2;
|
||||
|
||||
//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
|
||||
|
||||
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
|
||||
$mail->Port = 587;
|
||||
|
||||
//Set the encryption system to use - ssl (deprecated) or tls
|
||||
$mail->SMTPSecure = 'tls';
|
||||
|
||||
//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
|
||||
$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 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;
|
||||
}
|
||||
105
core/l/PHPMailer/examples/gmail_xoauth.phps
Executable file
105
core/l/PHPMailer/examples/gmail_xoauth.phps
Executable file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* This example shows how to send via Google's Gmail servers using XOAUTH2 authentication.
|
||||
*/
|
||||
|
||||
//Import PHPMailer classes into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
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
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 2;
|
||||
|
||||
//Set the hostname of the mail server
|
||||
$mail->Host = 'smtp.gmail.com';
|
||||
|
||||
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
|
||||
$mail->Port = 587;
|
||||
|
||||
//Set the encryption system to use - ssl (deprecated) or tls
|
||||
$mail->SMTPSecure = 'tls';
|
||||
|
||||
//Whether to use SMTP authentication
|
||||
$mail->SMTPAuth = true;
|
||||
|
||||
//Set AuthType to use XOAUTH2
|
||||
$mail->AuthType = 'XOAUTH2';
|
||||
|
||||
//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,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
//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 = 'utf-8';
|
||||
$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!";
|
||||
}
|
||||
BIN
core/l/PHPMailer/examples/images/phpmailer.png
Executable file
BIN
core/l/PHPMailer/examples/images/phpmailer.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
core/l/PHPMailer/examples/images/phpmailer_mini.png
Executable file
BIN
core/l/PHPMailer/examples/images/phpmailer_mini.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
34
core/l/PHPMailer/examples/mail.phps
Executable file
34
core/l/PHPMailer/examples/mail.phps
Executable file
@@ -0,0 +1,34 @@
|
||||
<?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!";
|
||||
}
|
||||
65
core/l/PHPMailer/examples/mailing_list.phps
Executable file
65
core/l/PHPMailer/examples/mailing_list.phps
Executable file
@@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
error_reporting(E_STRICT | E_ALL);
|
||||
|
||||
date_default_timezone_set('Etc/UTC');
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
$mail = new PHPMailer;
|
||||
|
||||
$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->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) {
|
||||
$mail->addAddress($row['email'], $row['full_name']);
|
||||
if (!empty($row['photo'])) {
|
||||
$mail->addStringAttachment($row['photo'], 'YourPhoto.jpg'); //Assumes the image data is stored in the DB
|
||||
}
|
||||
|
||||
if (!$mail->send()) {
|
||||
echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
|
||||
break; //Abandon sending
|
||||
} else {
|
||||
echo "Message sent to :" . $row['full_name'] . ' (' . str_replace("@", "@", $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']) . "'"
|
||||
);
|
||||
}
|
||||
// Clear all addresses and attachments for next loop
|
||||
$mail->clearAddresses();
|
||||
$mail->clearAttachments();
|
||||
}
|
||||
58
core/l/PHPMailer/examples/pop_before_smtp.phps
Executable file
58
core/l/PHPMailer/examples/pop_before_smtp.phps
Executable file
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
|
||||
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
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 2;
|
||||
//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!
|
||||
}
|
||||
52
core/l/PHPMailer/examples/send_file_upload.phps
Executable file
52
core/l/PHPMailer/examples/send_file_upload.phps
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer simple file upload and send example.
|
||||
*/
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
$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
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name']));
|
||||
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
||||
// Upload handled successfully
|
||||
// Now create a message
|
||||
require '../vendor/autoload.php';
|
||||
$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
|
||||
$mail->addAttachment($uploadfile, 'My uploaded file');
|
||||
if (!$mail->send()) {
|
||||
$msg .= "Mailer Error: " . $mail->ErrorInfo;
|
||||
} else {
|
||||
$msg .= "Message sent!";
|
||||
}
|
||||
} else {
|
||||
$msg .= 'Failed to move file to ' . $uploadfile;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<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 $msg;
|
||||
} ?>
|
||||
</body>
|
||||
</html>
|
||||
53
core/l/PHPMailer/examples/send_multiple_file_upload.phps
Executable file
53
core/l/PHPMailer/examples/send_multiple_file_upload.phps
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer multiple files upload and send example
|
||||
*/
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
$msg = '';
|
||||
if (array_key_exists('userfile', $_FILES)) {
|
||||
require '../vendor/autoload.php';
|
||||
// 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; $ct < count($_FILES['userfile']['tmp_name']); $ct++) {
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct]));
|
||||
$filename = $_FILES['userfile']['name'][$ct];
|
||||
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
|
||||
$mail->addAttachment($uploadfile, $filename);
|
||||
} else {
|
||||
$msg .= 'Failed to move file to ' . $uploadfile;
|
||||
}
|
||||
}
|
||||
if (!$mail->send()) {
|
||||
$msg .= "Mailer Error: " . $mail->ErrorInfo;
|
||||
} else {
|
||||
$msg .= "Message sent!";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<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 $msg;
|
||||
} ?>
|
||||
</body>
|
||||
</html>
|
||||
36
core/l/PHPMailer/examples/sendmail.phps
Executable file
36
core/l/PHPMailer/examples/sendmail.phps
Executable file
@@ -0,0 +1,36 @@
|
||||
<?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!";
|
||||
}
|
||||
101
core/l/PHPMailer/examples/simple_contact_form.phps
Executable file
101
core/l/PHPMailer/examples/simple_contact_form.phps
Executable file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer simple contact form example.
|
||||
* If you want to accept and send uploads in your form, look at the send_file_upload example.
|
||||
*/
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
if (array_key_exists('to', $_POST)) {
|
||||
$err = false;
|
||||
$msg = '';
|
||||
$email = '';
|
||||
//Apply some basic validation and filtering to the subject
|
||||
if (array_key_exists('subject', $_POST)) {
|
||||
$subject = substr(strip_tags($_POST['subject']), 0, 255);
|
||||
} else {
|
||||
$subject = 'No subject given';
|
||||
}
|
||||
//Apply some basic validation and filtering to the query
|
||||
if (array_key_exists('query', $_POST)) {
|
||||
//Limit length and strip HTML tags
|
||||
$query = substr(strip_tags($_POST['query']), 0, 16384);
|
||||
} else {
|
||||
$query = '';
|
||||
$msg = 'No query provided!';
|
||||
$err = true;
|
||||
}
|
||||
//Apply some basic validation and filtering to the name
|
||||
if (array_key_exists('name', $_POST)) {
|
||||
//Limit length and strip HTML tags
|
||||
$name = substr(strip_tags($_POST['name']), 0, 255);
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
//Validate to address
|
||||
//Never allow arbitrary input for the 'to' address as it will turn your form into a spam gateway!
|
||||
//Substitute appropriate addresses from your own domain, or simply use a single, fixed address
|
||||
if (array_key_exists('to', $_POST) and in_array($_POST['to'], ['sales', 'support', 'accounts'])) {
|
||||
$to = $_POST['to'] . '@example.com';
|
||||
} else {
|
||||
$to = 'support@example.com';
|
||||
}
|
||||
//Make sure the address they provided is valid before trying to use it
|
||||
if (array_key_exists('email', $_POST) and PHPMailer::validateAddress($_POST['email'])) {
|
||||
$email = $_POST['email'];
|
||||
} else {
|
||||
$msg .= "Error: invalid email address provided";
|
||||
$err = true;
|
||||
}
|
||||
if (!$err) {
|
||||
$mail = new PHPMailer;
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'localhost';
|
||||
$mail->Port = 2500;
|
||||
$mail->CharSet = 'utf-8';
|
||||
//It's important not to use the submitter's address as the from address as it's forgery,
|
||||
//which will cause your messages to fail SPF checks.
|
||||
//Use an address in your own domain as the from address, put the submitter's address in a reply-to
|
||||
$mail->setFrom('contact@example.com', (empty($name) ? 'Contact form' : $name));
|
||||
$mail->addAddress($to);
|
||||
$mail->addReplyTo($email, $name);
|
||||
$mail->Subject = 'Contact form: ' . $subject;
|
||||
$mail->Body = "Contact form submission\n\n" . $query;
|
||||
if (!$mail->send()) {
|
||||
$msg .= "Mailer Error: " . $mail->ErrorInfo;
|
||||
} else {
|
||||
$msg .= "Message sent!";
|
||||
}
|
||||
}
|
||||
} ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>PHPMailer Contact Form</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Contact us</h1>
|
||||
<?php if (empty($msg)) { ?>
|
||||
<form method="post">
|
||||
<label for="to">Send to:</label>
|
||||
<select name="to" id="to">
|
||||
<option value="sales">Sales</option>
|
||||
<option value="support" selected="selected">Support</option>
|
||||
<option value="accounts">Accounts</option>
|
||||
</select><br>
|
||||
<label for="subject">Subject: <input type="text" name="subject" id="subject" maxlength="255"></label><br>
|
||||
<label for="name">Your name: <input type="text" name="name" id="name" maxlength="255"></label><br>
|
||||
<label for="email">Your email address: <input type="email" name="email" id="email" maxlength="255"></label><br>
|
||||
<label for="query">Your question:</label><br>
|
||||
<textarea cols="30" rows="8" name="query" id="query" placeholder="Your question"></textarea><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<?php } else {
|
||||
echo $msg;
|
||||
} ?>
|
||||
</body>
|
||||
</html>
|
||||
98
core/l/PHPMailer/examples/smime_signed_mail.phps
Executable file
98
core/l/PHPMailer/examples/smime_signed_mail.phps
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* This PHPMailer example shows S/MIME signing a message and then sending.
|
||||
*
|
||||
* Before you can sign the mail certificates are needed.
|
||||
*
|
||||
*
|
||||
* STEP 1 - Creating a certificate:
|
||||
* You can either use a self-signed certificate, pay for a signed one,
|
||||
* or use free alternatives such as StartSSL, Comodo etc.
|
||||
* Check out this link for more providers: http://kb.mozillazine.org/Getting_an_SMIME_certificate
|
||||
* In this example I am using Comodo.
|
||||
* The form is directly available via https://secure.comodo.com/products/frontpage?area=SecureEmailCertificate
|
||||
* Fill it out and you'll get an email with a link to download your certificate.
|
||||
* Usually the certificate will be directly installed into your browser (FireFox/Chrome).
|
||||
*
|
||||
*
|
||||
* STEP 2 - Exporting the certificate
|
||||
* This is specific to your browser, however, most browsers will give you the option
|
||||
* to export your recently added certificate in PKCS12 (.pfx)
|
||||
* Include your private key if you are asked for it.
|
||||
* Set up a password to protect your exported file.
|
||||
*
|
||||
* STEP 3 - Splitting the .pfx into a private key and the certificate.
|
||||
* I use openssl for this. You only need two commands. In my case the certificate file is called 'exported-cert.pfx'
|
||||
* To create the private key do the following:
|
||||
*
|
||||
* openssl pkcs12 -in exported-cert.pfx -nocerts -out cert.key
|
||||
*
|
||||
* Of course the way you name your file (-out) is up to you.
|
||||
* You will be asked for a password for the Import password. This is the password you
|
||||
* set while exporting the certificate into the pfx file.
|
||||
* Afterwards, you can password protect your private key (recommended)
|
||||
* Also make sure to set the permissions to a minimum level and suitable for your application.
|
||||
* To create the certificate file use the following command:
|
||||
*
|
||||
* openssl pkcs12 -in exported-cert.pfx -clcerts -nokeys -out cert.crt
|
||||
*
|
||||
* Again, the way you name your certificate is up to you. You will be also asked for the Import Password.
|
||||
* To create the certificate-chain file use the following command:
|
||||
*
|
||||
* openssl pkcs12 -in exported-cert.pfx -cacerts -out certchain.pem
|
||||
*
|
||||
* Again, the way you name your chain file is up to you. You will be also asked for the Import Password.
|
||||
*
|
||||
*
|
||||
* STEP 3 - Code
|
||||
*/
|
||||
|
||||
//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
|
||||
//IMPORTANT: This must match the email address of your certificate.
|
||||
//Although the certificate will be valid, an error will be thrown since it cannot be verified
|
||||
//that the sender and the signer are the same person.
|
||||
$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');
|
||||
|
||||
//Configure message signing (the actual signing does not occur until sending)
|
||||
$mail->sign(
|
||||
'/path/to/cert.crt', //The location of your certificate file
|
||||
'/path/to/cert.key', //The location of your private key file
|
||||
//The password you protected your private key with (not the Import Password!
|
||||
//May be empty but the parameter must not be omitted!
|
||||
'yourSecretPrivateKeyPassword',
|
||||
'/path/to/certchain.pem' //The location of your chain file
|
||||
);
|
||||
|
||||
//Send the message, check for errors
|
||||
if (!$mail->send()) {
|
||||
echo "Mailer Error: " . $mail->ErrorInfo;
|
||||
} else {
|
||||
echo "Message sent!";
|
||||
}
|
||||
/*
|
||||
* REMARKS:
|
||||
* If your email client does not support S/MIME it will most likely just show an attachment smime.p7s,
|
||||
* which is the signature contained in the email.
|
||||
* Other clients, such as Thunderbird support S/MIME natively and will validate the signature
|
||||
* automatically and report the result in some way.
|
||||
*/
|
||||
55
core/l/PHPMailer/examples/smtp.phps
Executable file
55
core/l/PHPMailer/examples/smtp.phps
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* This example shows making an SMTP connection with authentication.
|
||||
*/
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
//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');
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
//Create a new PHPMailer instance
|
||||
$mail = new PHPMailer;
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Enable SMTP debugging
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 2;
|
||||
//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 = true;
|
||||
//Username to use for SMTP authentication
|
||||
$mail->Username = 'yourname@example.com';
|
||||
//Password to use for SMTP authentication
|
||||
$mail->Password = 'yourpassword';
|
||||
//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 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!';
|
||||
}
|
||||
59
core/l/PHPMailer/examples/smtp_check.phps
Executable file
59
core/l/PHPMailer/examples/smtp_check.phps
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This uses the SMTP class alone to check that a connection can be made to an SMTP server,
|
||||
* authenticate, then disconnect
|
||||
*/
|
||||
|
||||
//Import the PHPMailer SMTP class into the global namespace
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
//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');
|
||||
|
||||
//Create a new SMTP instance
|
||||
$smtp = new SMTP;
|
||||
|
||||
//Enable connection-level debug output
|
||||
$smtp->do_debug = SMTP::DEBUG_CONNECTION;
|
||||
|
||||
try {
|
||||
//Connect to an SMTP server
|
||||
if (!$smtp->connect('mail.example.com', 25)) {
|
||||
throw new Exception('Connect failed');
|
||||
}
|
||||
//Say hello
|
||||
if (!$smtp->hello(gethostname())) {
|
||||
throw new Exception('EHLO failed: ' . $smtp->getError()['error']);
|
||||
}
|
||||
//Get the list of ESMTP services the server offers
|
||||
$e = $smtp->getServerExtList();
|
||||
//If server can do TLS encryption, use it
|
||||
if (is_array($e) && array_key_exists('STARTTLS', $e)) {
|
||||
$tlsok = $smtp->startTLS();
|
||||
if (!$tlsok) {
|
||||
throw new Exception('Failed to start encryption: ' . $smtp->getError()['error']);
|
||||
}
|
||||
//Repeat EHLO after STARTTLS
|
||||
if (!$smtp->hello(gethostname())) {
|
||||
throw new Exception('EHLO (2) failed: ' . $smtp->getError()['error']);
|
||||
}
|
||||
//Get new capabilities list, which will usually now include AUTH if it didn't before
|
||||
$e = $smtp->getServerExtList();
|
||||
}
|
||||
//If server supports authentication, do it (even if no encryption)
|
||||
if (is_array($e) && array_key_exists('AUTH', $e)) {
|
||||
if ($smtp->authenticate('username', 'password')) {
|
||||
echo "Connected ok!";
|
||||
} else {
|
||||
throw new Exception('Authentication failed: ' . $smtp->getError()['error']);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'SMTP error: ' . $e->getMessage(), "\n";
|
||||
}
|
||||
//Whatever happened, close the connection.
|
||||
$smtp->quit(true);
|
||||
130
core/l/PHPMailer/examples/smtp_low_memory.phps
Executable file
130
core/l/PHPMailer/examples/smtp_low_memory.phps
Executable file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* SMTP low memory example.
|
||||
*/
|
||||
|
||||
namespace PHPMailer\PHPMailer;
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* This class demonstrates sending an already-built RFC822 message via SMTP
|
||||
* by extending PHPMailer's SMTP class.
|
||||
* It uses less memory that PHPMailer's usual approach because it keeps
|
||||
* the message as a single string rather than splitting its lines into
|
||||
* an array, which can consume very large amounts of memory if you have
|
||||
* large attachments. The downside is that it's somewhat slower.
|
||||
* This is mainly of academic interest, but shows how you can change how
|
||||
* core classes work without having to alter the library itself.
|
||||
*/
|
||||
class SMTPLowMemory extends SMTP
|
||||
{
|
||||
public function data($msg_data)
|
||||
{
|
||||
//This will use the standard timelimit
|
||||
if (!$this->sendCommand('DATA', 'DATA', 354)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* The server is ready to accept data!
|
||||
* According to rfc821 we should not send more than 1000 characters on a single line (including the LE)
|
||||
* so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
|
||||
* smaller lines to fit within the limit.
|
||||
* We will also look for lines that start with a '.' and prepend an additional '.'.
|
||||
* NOTE: this does not count towards line-length limit.
|
||||
*/
|
||||
|
||||
// Normalize line breaks
|
||||
$msg_data = str_replace(["\r\n", "\r"], "\n", $msg_data);
|
||||
|
||||
/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
|
||||
* of the first line (':' separated) does not contain a space then it _should_ be a header and we will
|
||||
* process all lines before a blank line as headers.
|
||||
*/
|
||||
|
||||
$firstline = substr($msg_data, 0, strcspn($msg_data, "\n", 0));
|
||||
$field = substr($firstline, 0, strpos($firstline, ':'));
|
||||
$in_headers = false;
|
||||
if (!empty($field) && strpos($field, ' ') === false) {
|
||||
$in_headers = true;
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
$len = strlen($msg_data);
|
||||
while ($offset < $len) {
|
||||
//Get position of next line break
|
||||
$linelen = strcspn($msg_data, "\n", $offset);
|
||||
//Get the next line
|
||||
$line = substr($msg_data, $offset, $linelen);
|
||||
//Remember where we have got to
|
||||
$offset += ($linelen + 1);
|
||||
$lines_out = [];
|
||||
if ($in_headers and $line == '') {
|
||||
$in_headers = false;
|
||||
}
|
||||
//We need to break this line up into several smaller lines
|
||||
//This is a small micro-optimisation: isset($str[$len]) is equivalent to (strlen($str) > $len)
|
||||
while (isset($line[self::MAX_LINE_LENGTH])) {
|
||||
//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
|
||||
//so as to avoid breaking in the middle of a word
|
||||
$pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
|
||||
//Deliberately matches both false and 0
|
||||
if (!$pos) {
|
||||
//No nice break found, add a hard break
|
||||
$pos = self::MAX_LINE_LENGTH - 1;
|
||||
$lines_out[] = substr($line, 0, $pos);
|
||||
$line = substr($line, $pos);
|
||||
} else {
|
||||
//Break at the found point
|
||||
$lines_out[] = substr($line, 0, $pos);
|
||||
//Move along by the amount we dealt with
|
||||
$line = substr($line, $pos + 1);
|
||||
}
|
||||
//If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
|
||||
if ($in_headers) {
|
||||
$line = "\t" . $line;
|
||||
}
|
||||
}
|
||||
$lines_out[] = $line;
|
||||
|
||||
//Send the lines to the server
|
||||
foreach ($lines_out as $line_out) {
|
||||
//RFC2821 section 4.5.2
|
||||
if (!empty($line_out) and $line_out[0] == '.') {
|
||||
$line_out = '.' . $line_out;
|
||||
}
|
||||
$this->client_send($line_out . self::LE);
|
||||
}
|
||||
}
|
||||
|
||||
//Message data has been sent, complete the command
|
||||
//Increase timelimit for end of DATA command
|
||||
$savetimelimit = $this->Timelimit;
|
||||
$this->Timelimit = $this->Timelimit * 2;
|
||||
$result = $this->sendCommand('DATA END', '.', 250);
|
||||
//Restore timelimit
|
||||
$this->Timelimit = $savetimelimit;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to use a PHPMailer subclass to make it use our SMTP implementation.
|
||||
* @package PHPMailer\PHPMailer
|
||||
*/
|
||||
class PHPMailerLowMemory extends PHPMailer
|
||||
{
|
||||
/**
|
||||
* Patch in the new SMTP class.
|
||||
* @return SMTP
|
||||
*/
|
||||
public function getSMTPInstance()
|
||||
{
|
||||
if (!is_object($this->smtp)) {
|
||||
$this->smtp = new SMTPLowMemory;
|
||||
}
|
||||
|
||||
return $this->smtp;
|
||||
}
|
||||
}
|
||||
51
core/l/PHPMailer/examples/smtp_no_auth.phps
Executable file
51
core/l/PHPMailer/examples/smtp_no_auth.phps
Executable file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* This example shows making an SMTP connection without using authentication.
|
||||
*/
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
//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');
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
//Create a new PHPMailer instance
|
||||
$mail = new PHPMailer;
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Enable SMTP debugging
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 2;
|
||||
//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;
|
||||
//We don't need to set this as it's the default value
|
||||
//$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 SMTP without auth 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!";
|
||||
}
|
||||
75
core/l/PHPMailer/examples/ssl_options.phps
Executable file
75
core/l/PHPMailer/examples/ssl_options.phps
Executable file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* This example shows settings to use when sending over SMTP with TLS and custom connection options.
|
||||
*/
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
//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');
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
//Create a new PHPMailer instance
|
||||
$mail = new PHPMailer;
|
||||
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
|
||||
//Enable SMTP debugging
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 2;
|
||||
|
||||
//Set the hostname of the mail server
|
||||
$mail->Host = 'smtp.example.com';
|
||||
|
||||
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
|
||||
$mail->Port = 587;
|
||||
|
||||
//Set the encryption system to use - ssl (deprecated) or tls
|
||||
$mail->SMTPSecure = 'tls';
|
||||
|
||||
//Custom connection options
|
||||
//Note that these settings are INSECURE
|
||||
$mail->SMTPOptions = array(
|
||||
'ssl' => [
|
||||
'verify_peer' => true,
|
||||
'verify_depth' => 3,
|
||||
'allow_self_signed' => true,
|
||||
'peer_name' => 'smtp.example.com',
|
||||
'cafile' => '/etc/ssl/ca_cert.pem',
|
||||
],
|
||||
);
|
||||
|
||||
//Whether to use SMTP authentication
|
||||
$mail->SMTPAuth = true;
|
||||
|
||||
//Username to use for SMTP authentication - use full email address for gmail
|
||||
$mail->Username = 'username@example.com';
|
||||
|
||||
//Password to use for SMTP authentication
|
||||
$mail->Password = 'yourpassword';
|
||||
|
||||
//Set who the message is to be sent from
|
||||
$mail->setFrom('from@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 SMTP options 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__);
|
||||
|
||||
//Send the message, check for errors
|
||||
if (!$mail->send()) {
|
||||
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||
} else {
|
||||
echo 'Message sent!';
|
||||
}
|
||||
Reference in New Issue
Block a user