fixed FS#170: Update PHPMailer to 5.2.23, removed old con class phpmailer, added new external class to autoload

Dieser Commit ist enthalten in:
Oldperl 2017-07-06 11:20:32 +00:00
Ursprung 8fd4d8fc8c
Commit 478ab816d9
12 geänderte Dateien mit 0 neuen und 1206 gelöschten Zeilen

Datei anzeigen

@ -1,17 +0,0 @@
NEW CALLBACK FUNCTION:
======================
We have had requests for a method to process the results of sending emails
through PHPMailer. In this new release, we have implemented a callback
function that passes the results of each email sent (to, cc, and/or bcc).
We have provided an example that echos the results back to the screen. The
callback function can be used for any purpose. With minor modifications, the
callback function can be used to create CSV logs, post results to databases,
etc.
Please review the test.php script for the example.
It's pretty straight forward.
Enjoy!
Andy

Datei anzeigen

@ -1,55 +0,0 @@
CREATE DKIM KEYS and DNS Resource Record:
=========================================
To create DomainKeys Identified Mail keys, visit:
http://dkim.worxware.com/
... read the information, fill in the form, and download the ZIP file
containing the public key, private key, DNS Resource Record and instructions
to add to your DNS Zone Record, and the PHPMailer code to enable DKIM
digital signing.
/*** PROTECT YOUR PRIVATE & PUBLIC KEYS ***/
You need to protect your DKIM private and public keys from being viewed or
accessed. Add protection to your .htaccess file as in this example:
# secure htkeyprivate file
<Files .htkeyprivate>
order allow,deny
deny from all
</Files>
# secure htkeypublic file
<Files .htkeypublic>
order allow,deny
deny from all
</Files>
(the actual .htaccess additions are in the ZIP file sent back to you from
http://dkim.worxware.com/
A few notes on using DomainKey Identified Mail (DKIM):
You do not need to use PHPMailer to DKIM sign emails IF:
- you enable DomainKey support and add the DNS resource record
- you use your outbound mail server
If you are a third-party emailer that works on behalf of domain owners to
send their emails from your own server:
- you absolutely have to DKIM sign outbound emails
- the domain owner has to add the DNS resource record to match the
private key, public key, selector, identity, and domain that you create
- use caution with the "selector" ... at least one "selector" will already
exist in the DNS Zone Record of the domain at the domain owner's server
you need to ensure that the "selector" you use is unique
Note: since the IP address will not match the domain owner's DNS Zone record
you can be certain that email providers that validate based on DomainKey will
check the domain owner's DNS Zone record for your DNS resource record. Before
sending out emails on behalf of domain owners, ensure they have entered the
DNS resource record you provided them.
Enjoy!
Andy
PS. if you need additional information about DKIM, please see:
http://www.dkim.org/info/dkim-faq.html

Datei anzeigen

@ -1,23 +0,0 @@
If you are having problems connecting or sending emails through your SMTP server, please note:
1. The new rewrite of class.smtp.php provides more information about the processing/errors taking place
2. Use the debug functionality of class.smtp.php. To do that, in your own script add the debug level you wish to use. An example of that is:
$mail->SMTPDebug = 1;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 26; // set the SMTP port
$mail->Host = "mail.yourhost.com"; // SMTP server
$mail->Username = "name@yourhost.com"; // SMTP account username
$mail->Password = "your password"; // SMTP account password
Notes on this:
$mail->SMTPDebug = 0; ... will disable debugging (you can also leave this out completely, 0 is the default
$mail->SMTPDebug = 1; ... will echo errors and messages
$mail->SMTPDebug = 2; ... will echo messages only
... and finally, the options are 0, 1, and 2 ... any number greater than 2 will be interpreted as 2
And finally, don't forget to disable debugging before going into production.
Enjoy!
Andy

Datei anzeigen

@ -1,148 +0,0 @@
<html>
<head>
<title>Examples using phpmailer</title>
</head>
<body bgcolor="#FFFFFF">
<h2>Examples using phpmailer</h2>
<h3>1. Advanced Example</h3>
<p>
This demonstrates sending out multiple email messages with binary attachments
from a MySQL database with multipart/alternative support.<p>
<table cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="#CCCCCC">
<pre>
require("class.phpmailer.php");
$mail = new phpmailer();
$mail->From = "list@example.com";
$mail->FromName = "List manager";
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->Mailer = "smtp";
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";
$result = @MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result))
{
// HTML body
$body = "Hello &lt;font size=\"4\"&gt;" . $row["full_name"] . "&lt;/font&gt;, &lt;p&gt;";
$body .= "&lt;i&gt;Your&lt;/i&gt; personal photograph to this message.&lt;p&gt;";
$body .= "Sincerely, &lt;br&gt;";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["full_name"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send())
echo "There has been a mail error sending to " . $row["email"] . "&lt;br&gt;";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
</pre>
</td>
</tr>
</table>
<p>
<h3>2. Extending phpmailer</h3>
<p>
Extending classes with inheritance is one of the most
powerful features of object-oriented
programming. It allows you to make changes to the
original class for your
own personal use without hacking the original
classes. Plus, it is very
easy to do. I've provided an example:
<p>
Here's a class that extends the phpmailer class and sets the defaults
for the particular site:<br>
PHP include file: <b>mail.inc.php</b>
<p>
<table cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="#CCCCCC">
<pre>
require("class.phpmailer.php");
class my_phpmailer extends phpmailer {
// Set default variables for all new objects
var $From = "from@example.com";
var $FromName = "Mailer";
var $Host = "smtp1.example.com;smtp2.example.com";
var $Mailer = "smtp"; // Alternative to IsSMTP()
var $WordWrap = 75;
// Replace the default error_handler
function error_handler($msg) {
print("My Site Error");
print("Description:");
printf("%s", $msg);
exit;
}
// Create an additional function
function do_something($something) {
// Place your new code here
}
}
</td>
</tr>
</table>
<br>
Now here's a normal PHP page in the site, which will have all the defaults set
above:<br>
Normal PHP file: <b>mail_test.php</b>
<p>
<table cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="#CCCCCC">
<pre>
require("mail.inc.php");
// Instantiate your new class
$mail = new my_phpmailer;
// Now you only need to add the necessary stuff
$mail->AddAddress("josh@example.com", "Josh Adams");
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip"); // optional name
if(!$mail->Send())
{
echo "There was an error sending the message";
exit;
}
echo "Message was sent successfully";
</pre>
</td>
</tr>
</table>
</p>
</body>
</html>

Datei anzeigen

@ -1,67 +0,0 @@
<html>
<head>
<title>PHPMailer FAQ</title>
<style>
body, p {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
div.width {
width: 500px;
text-align: left;
}
</style>
</head>
<body bgcolor="#FFFFFF">
<center>
<div class="width">
<h2>PHPMailer FAQ</h2>
<ul>
<li><b style="background-color: #FFFF00">Q:</b> <b>I&#039;m using the SMTP mailer and I keep on getting a timeout message
well before the X seconds I set it for. What gives?</b><br />
<b style="background-color: #FFFF00">A:</b> PHP versions 4.0.4pl1 and earlier have a bug in which sockets timeout
early. You can fix this by re-compiling PHP 4.0.4pl1 with this fix:
<a href="timeoutfix.diff">timeoutfix.diff</a>. Otherwise you can wait for the new PHP release.<br /><br /></li>
<li><b style="background-color: #FFFF00">Q:</b> <b>I am concerned that using include files will take up too much
processing time on my computer. How can I make it run faster?</b><br />
<b style="background-color: #FFFF00">A:</b> PHP by itself is very fast. Much faster than ASP or JSP running on
the same type of server. This is because it has very little overhead compared
to its competitors and it pre-compiles all of
its code before it runs each script (in PHP4). However, all of
this compiling and re-compiling can take up a lot of valuable
computer resources. However, there are programs out there that compile
PHP code and store it in memory (or on mmaped files) to reduce the
processing immensely. Two of these: <a href="http://apc.communityconnect.com">APC
(Alternative PHP Cache)</a> and <a href="http://bwcache.bware.it/index.htm">Afterburner</a>
(<a href="http://www.mm4.de/php4win/mod_php4_win32/">Win32 download</a>)
are excellent free tools that do just this. If you have the money
you might also try <a href="http://www.zend.com">Zend Cache</a>, it is
even faster than the open source varieties. All of these tools make your
scripts run faster while also reducing the load on your server. I have tried
them myself and they are quite stable too.<br /><br /></li>
<li><b style="background-color: #FFFF00">Q:</b> <b>What mailer gives me the best performance?</b><br />
<b style="background-color: #FFFF00">A:</b> On a single machine the <b>sendmail (or Qmail)</b> is fastest overall.
Next fastest is mail() to give you the best performance. Both do not have the overhead of SMTP.
If you have you have your mail server on a another machine then
SMTP is your only option, but you do get the benefit of redundant mail servers.<br />
If you are running a mailing list with thousands of names, the fastest mailers in order are: SMTP, sendmail (or Qmail), mail().<br /><br /></li>
<li><b style="background-color: #FFFF00">Q:</b> <b>When I try to attach a file with on my server I get a
"Could not find {file} on filesystem error". Why is this?</b><br />
<b style="background-color: #FFFF00">A:</b> If you are using a Unix machine this is probably because the user
running your web server does not have read access to the directory in question. If you are using Windows,
then the problem probably is that you have used single backslashes to denote directories (\).
A single backslash has a special meaning to PHP so these are not
valid. Instead use double backslashes ("\\") or a single forward
slash ("/").<br /><br /></li>
</ul>
</div>
</center>
</body>
</html>

Datei anzeigen

@ -1,39 +0,0 @@
This is built for PHP Mailer 1.72 and was not tested with any previous version. It was developed under PHP 4.3.11 (E_ALL). It works under PHP 5 and 5.1 with E_ALL, but not in Strict mode due to var deprecation (but then neither does PHP Mailer either!). It follows the RFC 1939 standard explicitly and is fully commented.
With that noted, here is how to implement it:
Install the class file
I didn't want to modify the PHP Mailer classes at all, so you will have to include/require this class along with the base one. It can sit quite happily in the phpmailer-1.72 directory:
[geshi lang=php] require 'phpmailer-1.72/class.phpmailer.php'; require 'phpmailer-1.72/class.pop3.php'; [/geshi]
When you need it, create your POP3 object
Right before I invoke PHP Mailer I activate the POP3 authorisation. POP3 before SMTP is a process whereby you login to your web hosts POP3 mail server BEFORE sending out any emails via SMTP. The POP3 logon 'verifies' your ability to send email by SMTP, which typically otherwise blocks you. On my web host (Pair Networks) a single POP3 logon is enough to 'verify' you for 90 minutes. Here is some sample PHP code that activates the POP3 logon and then sends an email via PHP Mailer:
[geshi lang=php] Authorise('pop3.example.com', 110, 30, 'mailer', 'password', 1); $mail = new PHPMailer(); $mail->SMTPDebug = 2; $mail->IsSMTP(); $mail->IsHTML(false); $mail->Host = 'relay.example.com'; $mail->From = 'mailer@example.com'; $mail->FromName = 'Example Mailer'; $mail->Subject = 'My subject'; $mail->Body = 'Hello world'; $mail->AddAddress('rich@corephp.co.uk', 'Richard Davey'); if (!$mail->Send()) { echo $mail->ErrorInfo; } ?> [/geshi]
The PHP Mailer parts of this code should be obvious to anyone who has used PHP Mailer before. One thing to note - you almost certainly will not need to use SMTP Authentication *and* POP3 before SMTP together. The Authorisation method is a proxy method to all of the others within that class. There are Connect, Logon and Disconnect methods available, but I wrapped them in the single Authorisation one to make things easier.
The Parameters
The Authorise parameters are as follows:
[geshi lang=php]$pop->Authorise('pop3.example.com', 110, 30, 'mailer', 'password', 1);[/geshi]
1. pop3.example.com - The POP3 Mail Server Name (hostname or IP address)
2. 110 - The POP3 Port on which to connect (default is usually 110, but check with your host)
3. 30 - A connection time-out value (in seconds)
4. mailer - The POP3 Username required to logon
5. password - The POP3 Password required to logon
6. 1 - The class debug level (0 = off, 1+ = debug output is echoed to the browser)
Final Comments + the Download
1) This class does not support APOP connections. This is only because I did not have an APOP server to test with, but if you'd like to see that added just contact me.
2) Opening and closing lots of POP3 connections can be quite a resource/network drain. If you need to send a whole batch of emails then just perform the authentication once at the start, and then loop through your mail sending script. Providing this process doesn't take longer than the verification period lasts on your POP3 server, you should be fine. With my host that period is 90 minutes, i.e. plenty of time.
3) If you have heavy requirements for this script (i.e. send a LOT of email on a frequent basis) then I would advise seeking out an alternative sending method (direct SMTP ideally). If this isn't possible then you could modify this class so the 'last authorised' date is recorded somewhere (MySQL, Flat file, etc) meaning you only open a new connection if the old one has expired, saving you precious overhead.
4) There are lots of other POP3 classes for PHP available. However most of them implement the full POP3 command set, where-as this one is purely for authentication, and much lighter as a result. However using any of the other POP3 classes to just logon to your server would have the same net result. At the end of the day, use whatever method you feel most comfortable with.
Download
Here is the full class file plus my test script: POP_before_SMTP_PHPMailer.zip (4 KB) - Please note that it does not include PHPMailer itself.
My thanks to Chris Ryan for the inspiration (even if indirectly, via his SMTP class)

Datei anzeigen

@ -1,45 +0,0 @@
<?php
// example on using PHPMailer with GMAIL
include("class.phpmailer.php");
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "yourname@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->From = "replyto@yourdomain.com";
$mail->FromName = "Webmaster";
$mail->Subject = "This is the subject";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("replyto@yourdomain.com","Webmaster");
$mail->AddAttachment("/path/to/file.zip"); // attachment
$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
$mail->AddAddress("username@domain.com","First Last");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>

Datei anzeigen

@ -1,10 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Email test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Here is a test HTML email</p>
</body>
</html>

Datei anzeigen

@ -1,670 +0,0 @@
<?php
/**
* PHPMailer - PHP email transport unit tests
* Before running these tests you need to install PHPUnit 3.3 or later through pear, like this:
* pear install "channel://pear.phpunit.de/PHPUnit"
* Then run the tests like this:
* phpunit phpmailerTest
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @version $Id: phpmailerTest.php 73 2012-05-24 16:08:11Z oldperl $
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require 'PHPUnit/Framework.php';
$INCLUDE_DIR = "../";
require $INCLUDE_DIR . 'class.phpmailer.php';
error_reporting(E_ALL);
/**
* PHPMailer - PHP email transport unit test class
* Performs authentication tests
*/
class phpmailerTest extends PHPUnit_Framework_TestCase {
/**
* Holds the default phpmailer instance.
* @private
* @type object
*/
var $Mail = false;
/**
* Holds the SMTP mail host.
* @public
* @type string
*/
var $Host = "";
/**
* Holds the change log.
* @private
* @type string array
*/
var $ChangeLog = array();
/**
* Holds the note log.
* @private
* @type string array
*/
var $NoteLog = array();
/**
* Run before each test is started.
*/
function setUp() {
global $INCLUDE_DIR;
@include './testbootstrap.php'; //Overrides go in here
$this->Mail = new PHPMailer();
$this->Mail->Priority = 3;
$this->Mail->Encoding = "8bit";
$this->Mail->CharSet = "iso-8859-1";
if (array_key_exists('mail_from', $_REQUEST)) {
$this->Mail->From = $_REQUEST['mail_from'];
} else {
$this->Mail->From = 'unit_test@phpmailer.sf.net';
}
$this->Mail->FromName = "Unit Tester";
$this->Mail->Sender = "";
$this->Mail->Subject = "Unit Test";
$this->Mail->Body = "";
$this->Mail->AltBody = "";
$this->Mail->WordWrap = 0;
if (array_key_exists('mail_host', $_REQUEST)) {
$this->Mail->Host = $_REQUEST['mail_host'];
} else {
$this->Mail->Host = 'mail.example.com';
}
$this->Mail->Port = 25;
$this->Mail->Helo = "localhost.localdomain";
$this->Mail->SMTPAuth = false;
$this->Mail->Username = "";
$this->Mail->Password = "";
$this->Mail->PluginDir = $INCLUDE_DIR;
$this->Mail->AddReplyTo("no_reply@phpmailer.sf.net", "Reply Guy");
$this->Mail->Sender = "unit_test@phpmailer.sf.net";
if(strlen($this->Mail->Host) > 0) {
$this->Mail->Mailer = "smtp";
} else {
$this->Mail->Mailer = "mail";
$this->Sender = "unit_test@phpmailer.sf.net";
}
if (array_key_exists('mail_to', $_REQUEST)) {
$this->SetAddress($_REQUEST['mail_to'], 'Test User', 'to');
}
if (array_key_exists('mail_cc', $_REQUEST) and strlen($_REQUEST['mail_cc']) > 0) {
$this->SetAddress($_REQUEST['mail_cc'], 'Carbon User', 'cc');
}
}
/**
* Run after each test is completed.
*/
function tearDown() {
// Clean global variables
$this->Mail = NULL;
$this->ChangeLog = array();
$this->NoteLog = array();
}
/**
* Build the body of the message in the appropriate format.
* @private
* @returns void
*/
function BuildBody() {
$this->CheckChanges();
// Determine line endings for message
if($this->Mail->ContentType == "text/html" || strlen($this->Mail->AltBody) > 0)
{
$eol = "<br/>";
$bullet = "<li>";
$bullet_start = "<ul>";
$bullet_end = "</ul>";
}
else
{
$eol = "\n";
$bullet = " - ";
$bullet_start = "";
$bullet_end = "";
}
$ReportBody = "";
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "Unit Test Information" . $eol;
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "phpmailer version: " . PHPMailer::VERSION . $eol;
$ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol;
if(strlen($this->Mail->Host) > 0)
$ReportBody .= "Host: " . $this->Mail->Host . $eol;
// If attachments then create an attachment list
$attachments = $this->Mail->GetAttachments();
if(count($attachments) > 0)
{
$ReportBody .= "Attachments:" . $eol;
$ReportBody .= $bullet_start;
foreach($attachments as $attachment) {
$ReportBody .= $bullet . "Name: " . $attachment[1] . ", ";
$ReportBody .= "Encoding: " . $attachment[3] . ", ";
$ReportBody .= "Type: " . $attachment[4] . $eol;
}
$ReportBody .= $bullet_end . $eol;
}
// If there are changes then list them
if(count($this->ChangeLog) > 0)
{
$ReportBody .= "Changes" . $eol;
$ReportBody .= "-------" . $eol;
$ReportBody .= $bullet_start;
for($i = 0; $i < count($this->ChangeLog); $i++)
{
$ReportBody .= $bullet . $this->ChangeLog[$i][0] . " was changed to [" .
$this->ChangeLog[$i][1] . "]" . $eol;
}
$ReportBody .= $bullet_end . $eol . $eol;
}
// If there are notes then list them
if(count($this->NoteLog) > 0)
{
$ReportBody .= "Notes" . $eol;
$ReportBody .= "-----" . $eol;
$ReportBody .= $bullet_start;
for($i = 0; $i < count($this->NoteLog); $i++)
{
$ReportBody .= $bullet . $this->NoteLog[$i] . $eol;
}
$ReportBody .= $bullet_end;
}
// Re-attach the original body
$this->Mail->Body .= $eol . $eol . $ReportBody;
}
/**
* Check which default settings have been changed for the report.
* @private
* @returns void
*/
function CheckChanges() {
if($this->Mail->Priority != 3)
$this->AddChange("Priority", $this->Mail->Priority);
if($this->Mail->Encoding != "8bit")
$this->AddChange("Encoding", $this->Mail->Encoding);
if($this->Mail->CharSet != "iso-8859-1")
$this->AddChange("CharSet", $this->Mail->CharSet);
if($this->Mail->Sender != "")
$this->AddChange("Sender", $this->Mail->Sender);
if($this->Mail->WordWrap != 0)
$this->AddChange("WordWrap", $this->Mail->WordWrap);
if($this->Mail->Mailer != "mail")
$this->AddChange("Mailer", $this->Mail->Mailer);
if($this->Mail->Port != 25)
$this->AddChange("Port", $this->Mail->Port);
if($this->Mail->Helo != "localhost.localdomain")
$this->AddChange("Helo", $this->Mail->Helo);
if($this->Mail->SMTPAuth)
$this->AddChange("SMTPAuth", "true");
}
/**
* Adds a change entry.
* @private
* @returns void
*/
function AddChange($sName, $sNewValue) {
$cur = count($this->ChangeLog);
$this->ChangeLog[$cur][0] = $sName;
$this->ChangeLog[$cur][1] = $sNewValue;
}
/**
* Adds a simple note to the message.
* @public
* @returns void
*/
function AddNote($sValue) {
$this->NoteLog[] = $sValue;
}
/**
* Adds all of the addresses
* @public
* @returns void
*/
function SetAddress($sAddress, $sName = "", $sType = "to") {
switch($sType)
{
case "to":
return $this->Mail->AddAddress($sAddress, $sName);
case "cc":
return $this->Mail->AddCC($sAddress, $sName);
case "bcc":
return $this->Mail->AddBCC($sAddress, $sName);
}
}
/////////////////////////////////////////////////
// UNIT TESTS
/////////////////////////////////////////////////
/**
* Try a plain message.
*/
function test_WordWrap() {
$this->Mail->WordWrap = 40;
$my_body = "Here is the main body of this message. It should " .
"be quite a few lines. It should be wrapped at the " .
"40 characters. Make sure that it is.";
$nBodyLen = strlen($my_body);
$my_body .= "\n\nThis is the above body length: " . $nBodyLen;
$this->Mail->Body = $my_body;
$this->Mail->Subject .= ": Wordwrap";
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Try a plain message.
*/
function test_Low_Priority() {
$this->Mail->Priority = 5;
$this->Mail->Body = "Here is the main body. There should be " .
"a reply to address in this message.";
$this->Mail->Subject .= ": Low Priority";
$this->Mail->AddReplyTo("nobody@nobody.com", "Nobody (Unit Test)");
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Simple plain file attachment test.
*/
function test_Multiple_Plain_FileAttachment() {
$this->Mail->Body = "Here is the text body";
$this->Mail->Subject .= ": Plain + Multiple FileAttachments";
if(!$this->Mail->AddAttachment("test.png"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if(!$this->Mail->AddAttachment(__FILE__, "test.txt"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Simple plain string attachment test.
*/
function test_Plain_StringAttachment() {
$this->Mail->Body = "Here is the text body";
$this->Mail->Subject .= ": Plain + StringAttachment";
$sAttachment = "These characters are the content of the " .
"string attachment.\nThis might be taken from a ".
"database or some other such thing. ";
$this->Mail->AddStringAttachment($sAttachment, "string_attach.txt");
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Plain quoted-printable message.
*/
function test_Quoted_Printable() {
$this->Mail->Body = "Here is the main body";
$this->Mail->Subject .= ": Plain + Quoted-printable";
$this->Mail->Encoding = "quoted-printable";
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
//Check that a quoted printable encode and decode results in the same as went in
$t = substr(file_get_contents(__FILE__), 0, 1024); //Just pick a chunk of this file as test content
$this->assertEquals($t, quoted_printable_decode($this->Mail->EncodeQP($t)), 'QP encoding round-trip failed');
//$this->assertEquals($t, quoted_printable_decode($this->Mail->EncodeQPphp($t)), 'Native PHP QP encoding round-trip failed'); //TODO the PHP qp encoder is quite broken
}
/**
* Try a plain message.
*/
function test_Html() {
$this->Mail->IsHTML(true);
$this->Mail->Subject .= ": HTML only";
$this->Mail->Body = "This is a <b>test message</b> written in HTML. </br>" .
"Go to <a href=\"http://phpmailer.sourceforge.net/\">" .
"http://phpmailer.sourceforge.net/</a> for new versions of " .
"phpmailer. <p/> Thank you!";
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Simple HTML and attachment test
*/
function test_HTML_Attachment() {
$this->Mail->Body = "This is the <b>HTML</b> part of the email.";
$this->Mail->Subject .= ": HTML + Attachment";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddAttachment(__FILE__, "test_attach.txt"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* An embedded attachment test.
*/
function test_Embedded_Image() {
$this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
"Here is an image!</a>";
$this->Mail->Subject .= ": Embedded Image";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddEmbeddedImage("test.png", "my-attach", "test.png",
"base64", "image/png"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
//For code coverage
$this->Mail->AddEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file
$this->Mail->AddEmbeddedImage(__FILE__, '123'); //Missing name
}
/**
* An embedded attachment test.
*/
function test_Multi_Embedded_Image() {
$this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
"Here is an image!</a>";
$this->Mail->Subject .= ": Embedded Image + Attachment";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddEmbeddedImage("test.png", "my-attach", "test.png",
"base64", "image/png"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if(!$this->Mail->AddAttachment(__FILE__, "test.txt"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Simple multipart/alternative test.
*/
function test_AltBody() {
$this->Mail->Body = "This is the <b>HTML</b> part of the email.";
$this->Mail->AltBody = "Here is the text body of this message. " .
"It should be quite a few lines. It should be wrapped at the " .
"40 characters. Make sure that it is.";
$this->Mail->WordWrap = 40;
$this->AddNote("This is a mulipart alternative email");
$this->Mail->Subject .= ": AltBody + Word Wrap";
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Simple HTML and attachment test
*/
function test_AltBody_Attachment() {
$this->Mail->Body = "This is the <b>HTML</b> part of the email.";
$this->Mail->AltBody = "This is the text part of the email.";
$this->Mail->Subject .= ": AltBody + Attachment";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddAttachment(__FILE__, "test_attach.txt"))
{
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
if (is_writable('.')) {
file_put_contents('message.txt', $this->Mail->CreateHeader() . $this->Mail->CreateBody());
} else {
$this->assertTrue(false, 'Could not write local file - check permissions');
}
}
function test_MultipleSend() {
$this->Mail->Body = "Sending two messages without keepalive";
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->Subject = $subject . ": SMTP 1";
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->Subject = $subject . ": SMTP 2";
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
function test_SendmailSend() {
$this->Mail->Body = "Sending via sendmail";
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->Subject = $subject . ": sendmail";
$this->Mail->IsSendmail();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
function test_MailSend() {
$this->Mail->Body = "Sending via mail()";
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->Subject = $subject . ": mail()";
$this->Mail->IsMail();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
function test_SmtpKeepAlive() {
$this->Mail->Body = "This was done using the SMTP keep-alive.";
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->SMTPKeepAlive = true;
$this->Mail->Subject = $subject . ": SMTP keep-alive 1";
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->Subject = $subject . ": SMTP keep-alive 2";
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->SmtpClose();
}
/**
* Tests this denial of service attack:
* http://www.cybsec.com/vuln/PHPMailer-DOS.pdf
*/
function test_DenialOfServiceAttack() {
$this->Mail->Body = "This should no longer cause a denial of service.";
$this->BuildBody();
$this->Mail->Subject = str_repeat("A", 998);
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
function test_Error() {
$this->Mail->Subject .= ": This should be sent";
$this->BuildBody();
$this->Mail->ClearAllRecipients(); // no addresses should cause an error
$this->assertTrue($this->Mail->IsError() == false, "Error found");
$this->assertTrue($this->Mail->Send() == false, "Send succeeded");
$this->assertTrue($this->Mail->IsError(), "No error found");
$this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
$this->Mail->AddAddress($_REQUEST['mail_to']);
$this->assertTrue($this->Mail->Send(), "Send failed");
}
function test_Addressing() {
$this->assertFalse($this->Mail->AddAddress('a@example..com'), 'Invalid address accepted');
$this->assertTrue($this->Mail->AddAddress('a@example.com'), 'Addressing failed');
$this->assertFalse($this->Mail->AddAddress('a@example.com'), 'Duplicate addressing failed');
$this->assertTrue($this->Mail->AddCC('b@example.com'), 'CC addressing failed');
$this->assertFalse($this->Mail->AddCC('b@example.com'), 'CC duplicate addressing failed');
$this->assertFalse($this->Mail->AddCC('a@example.com'), 'CC duplicate addressing failed (2)');
$this->assertTrue($this->Mail->AddBCC('c@example.com'), 'BCC addressing failed');
$this->assertFalse($this->Mail->AddBCC('c@example.com'), 'BCC duplicate addressing failed');
$this->assertFalse($this->Mail->AddBCC('a@example.com'), 'BCC duplicate addressing failed (2)');
$this->assertTrue($this->Mail->AddReplyTo('a@example.com'), 'Replyto Addressing failed');
$this->assertFalse($this->Mail->AddReplyTo('a@example..com'), 'Invalid Replyto address accepted');
$this->Mail->ClearAddresses();
$this->Mail->ClearCCs();
$this->Mail->ClearBCCs();
$this->Mail->ClearReplyTos();
}
/**
* Test language files for missing and excess translations
* All languages are compared with English
*/
function test_Translations() {
$this->Mail->SetLanguage('en');
$definedStrings = $this->Mail->GetTranslations();
foreach (new DirectoryIterator('../language') as $fileInfo) {
if($fileInfo->isDot()) continue;
$matches = array();
//Only look at language files, ignore anything else in there
if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
$lang = $matches[1]; //Extract language code
$PHPMAILER_LANG = array(); //Language strings get put in here
include $fileInfo->getPathname(); //Get language strings
$missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
$extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
$this->assertTrue(empty($missing), "Missing translations in $lang: ". implode(', ', $missing));
$this->assertTrue(empty($extra), "Extra translations in $lang: ". implode(', ', $extra));
}
}
}
/**
* Encoding tests
*/
function test_Encodings() {
$this->Mail->Charset = 'iso-8859-1';
$this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('¡Hola! Señor!', 'text'), 'Q Encoding (text) failed');
$this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('¡Hola! Señor!', 'comment'), 'Q Encoding (comment) failed');
$this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('¡Hola! Señor!', 'phrase'), 'Q Encoding (phrase) failed');
}
/**
* Signing tests
*/
function test_Signing() {
$this->Mail->Sign('certfile.txt', 'keyfile.txt', 'password'); //TODO this is not really testing signing, but at least helps coverage
}
/**
* Miscellaneous calls to improve test coverage and some small tests
*/
function test_Miscellaneous() {
$this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf') , 'MIME TYPE lookup failed');
$this->Mail->AddCustomHeader('SomeHeader: Some Value');
$this->Mail->ClearCustomHeaders();
$this->Mail->ClearAttachments();
$this->Mail->IsHTML(false);
$this->Mail->IsSMTP();
$this->Mail->IsMail();
$this->Mail->IsSendMail();
$this->Mail->IsQmail();
$this->Mail->SetLanguage('fr');
$this->Mail->Sender = '';
$this->Mail->CreateHeader();
$this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
$this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
$this->Mail->getFile(__FILE__);
}
}
/**
* This is a sample form for setting appropriate test values through a browser
* These values can also be set using a file called testbootstrap.php (not in svn) in the same folder as this script
* which is probably more useful if you run these tests a lot
<html>
<body>
<h3>phpmailer Unit Test</h3>
By entering a SMTP hostname it will automatically perform tests with SMTP.
<form name="phpmailer_unit" action=__FILE__ method="get">
<input type="hidden" name="submitted" value="1"/>
From Address: <input type="text" size="50" name="mail_from" value="<?php echo get("mail_from"); ?>"/>
<br/>
To Address: <input type="text" size="50" name="mail_to" value="<?php echo get("mail_to"); ?>"/>
<br/>
Cc Address: <input type="text" size="50" name="mail_cc" value="<?php echo get("mail_cc"); ?>"/>
<br/>
SMTP Hostname: <input type="text" size="50" name="mail_host" value="<?php echo get("mail_host"); ?>"/>
<p/>
<input type="submit" value="Run Test"/>
</form>
</body>
</html>
*/
?>

Binäre Datei nicht angezeigt.

Vorher

Breite:  |  Höhe:  |  Größe: 1.3 KiB

Datei anzeigen

@ -1,84 +0,0 @@
<html>
<head>
<title>PHPMailer Lite - DKIM and Callback Function test</title>
</head>
<body>
<?php
/* This is a sample callback function for PHPMailer Lite.
* This callback function will echo the results of PHPMailer processing.
*/
/* Callback (action) function
* bool $result result of the send action
* string $to email address of the recipient
* string $cc cc email addresses
* string $bcc bcc email addresses
* string $subject the subject
* string $body the email body
* @return boolean
*/
function callbackAction ($result, $to, $cc, $bcc, $subject, $body) {
/*
this callback example echos the results to the screen - implement to
post to databases, build CSV log files, etc., with minor changes
*/
$to = cleanEmails($to,'to');
$cc = cleanEmails($cc[0],'cc');
$bcc = cleanEmails($bcc[0],'cc');
echo $result . "\tTo: " . $to['Name'] . "\tTo: " . $to['Email'] . "\tCc: " . $cc['Name'] . "\tCc: " . $cc['Email'] . "\tBcc: " . $bcc['Name'] . "\tBcc: " . $bcc['Email'] . "\t" . $subject . "<br />\n";
return true;
}
$testLite = false;
if ($testLite) {
require_once '../class.phpmailer-lite.php';
$mail = new PHPMailerLite();
} else {
require_once '../class.phpmailer.php';
$mail = new PHPMailer();
}
try {
$mail->IsMail(); // telling the class to use SMTP
$mail->SetFrom('you@yourdomain.com', 'Your Name');
$mail->AddAddress('another@yourdomain.com', 'John Doe');
$mail->Subject = 'PHPMailer Lite Test Subject via Mail()';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->action_function = 'callbackAction';
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
function cleanEmails($str,$type) {
if ($type == 'cc') {
$addy['Email'] = $str[0];
$addy['Name'] = $str[1];
return $addy;
}
if (!strstr($str, ' <')) {
$addy['Name'] = '';
$addy['Email'] = $addy;
return $addy;
}
$addyArr = explode(' <', $str);
if (substr($addyArr[1],-1) == '>') {
$addyArr[1] = substr($addyArr[1],0,-1);
}
$addy['Name'] = $addyArr[0];
$addy['Email'] = $addyArr[1];
$addy['Email'] = str_replace('@', '&#64;', $addy['Email']);
return $addy;
}
?>
</body>
</html>

Datei anzeigen

@ -1,48 +0,0 @@
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id: testemail.php 73 2012-05-24 16:08:11Z oldperl $
*/
require '../class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = file_get_contents('contents.html');
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->Username = "name@domain.com"; // SMTP server username
$mail->Password = "password"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("name@domain.com","First Last");
$mail->From = "name@domain.com";
$mail->FromName = "First Last";
$to = "someone@example...com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>