PSR-2 reformat

This commit is contained in:
Synchro 2013-07-22 13:05:16 +02:00
parent d79afc52c8
commit 03d8f1b498
22 changed files with 5332 additions and 5267 deletions

View File

@ -312,7 +312,7 @@ of these things:
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
e) verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the

View File

@ -7,7 +7,7 @@ Build status: [![Build Status](https://travis-ci.org/Synchro/PHPMailer.png)](htt
- Probably the world's most popular code for sending email from PHP!
- Used by many open-source projects: Drupal, SugarCRM, Yii, Joomla! and many more
- Integrated SMTP support - send without a local mail server
- Send emails with multiple TOs, CCs, BCCs and REPLY-TOs
- send emails with multiple TOs, CCs, BCCs and REPLY-TOs
- Multipart/alternative emails for mail clients that do not read HTML email
- Support for 8bit, base64, binary, and quoted-printable encoding
- SMTP authentication with LOGIN, PLAIN, NTLM and CRAM-MD5 mechanisms
@ -42,7 +42,7 @@ require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
@ -51,22 +51,22 @@ $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->AddAddress('josh@example.net', 'Josh Adams'); // Add a recipient
$mail->AddAddress('ellen@example.com'); // Name is optional
$mail->AddReplyTo('info@example.com', 'Information');
$mail->AddCC('cc@example.com');
$mail->AddBCC('bcc@example.com');
$mail->addAddress('josh@example.net', 'Josh Adams'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->AddAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->AddAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->IsHTML(true); // Set email format to HTML
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
@ -84,7 +84,7 @@ PHPMailer defaults to English, but in the `languages` folder you'll find numerou
```php
// To load the French version
$mail->SetLanguage('fr', '/optional/path/to/language/directory/');
$mail->setLanguage('fr', '/optional/path/to/language/directory/');
```
## Documentation

View File

@ -1,5 +1,6 @@
# ChangeLog
## Version 5.2.7 ()
* Add Ukranian translation from @Krezalis
* Support for do_verp
* Fix bug in CRAM-MD5 AUTH
@ -14,19 +15,23 @@
* Update SyntaxHighlighter
* Major overhaul and cleanup of example code
* New PHPMailer graphic
* MsgHTML now uses RFC2392-compliant content ids
* Add line break normalization function and use it in MsgHTML
* msgHTML now uses RFC2392-compliant content ids
* Add line break normalization function and use it in msgHTML
* Don't set unnecessary reply-to addresses
* Make fakesendmail.sh a bit cleaner and safer
* Set a content-transfer-encoding on multiparts (fixes msglint error)
* Fix cid generation in MsgHTML (Thanks to @digitalthought)
* Fix cid generation in msgHTML (Thanks to @digitalthought)
* Fix handling of multiple SMTP servers (Thanks to @NanoCaiordo)
* SMTP->Connect() now supports stream context options (Thanks to @stanislavdavid)
* SMTP->connect() now supports stream context options (Thanks to @stanislavdavid)
* Add support for iCal event alternatives (Thanks to @reblutus)
* Update to Polish language file (Thanks to Krzysztof Kowalewski)
* Update to Norwegian language file (Thanks to @datagutten)
* Update to Hungarian language file (Thanks to @dominicus-75)
* Add Persian/Farsi translation from @jaii
* Make SMTPDebug property type match type in SMTP class
* Add unit tests for DKIM
* Major refactor of SMTP class
* Reformat to PSR-2 coding standard
## Version 5.2.6 (April 11th 2013)
* Reflect move to PHPMailer GitHub organisation at https://github.com/PHPMailer/PHPMailer

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +1,27 @@
<?php
/*~ class.pop3.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Version: 5.2.6 |
| Site: https://github.com/PHPMailer/PHPMailer/ |
| ------------------------------------------------------------------------- |
| Admins: Marcus Bointon |
| Admins: Jim Jagielski |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| : Jim Jagielski (jimjag) jimjag@gmail.com |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved. |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
'---------------------------------------------------------------------------'
*/
/**
* PHPMailer - PHP POP Before SMTP Authentication Class
* NOTE: Designed for use with PHP version 5 and up
* PHPMailer - PHP POP-Before-SMTP Authentication Class
*
* PHP Version 5.0.0
*
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @author Jim Jagielski
* @link https://github.com/PHPMailer/PHPMailer/
* @author Marcus Bointon (coolbru) phpmailer@synchromedia.co.uk
* @author Jim Jagielski (jimjag) jimjag@gmail.com
* @author Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net
* @author Brent R. Matzelle (original founder)
* @copyright 2013 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* PHP POP-Before-SMTP Authentication Class
*
* Version 5.2.6
*
* @license: LGPL, see PHPMailer License
*
* Specifically for PHPMailer to allow POP before SMTP authentication.
@ -57,362 +39,324 @@
* @author Jim Jagielski
*/
class POP3 {
/**
* Default POP3 port
* @var int
*/
public $POP3_PORT = 110;
class POP3
{
/**
* @var string The POP3 PHPMailer Version number
*/
public $Version = '5.2.6';
/**
* Default Timeout
* @var int
*/
public $POP3_TIMEOUT = 30;
/**
* @var int Default POP3 port number
*/
public $POP3_PORT = 110;
/**
* POP3 Carriage Return + Line Feed
* @var string
*/
public $CRLF = "\r\n";
/**
* @var int Default Timeout in seconds
*/
public $POP3_TIMEOUT = 30;
/**
* Displaying Debug warnings? (0 = now, 1+ = yes)
* @var int
*/
public $do_debug = 2;
/**
* @var string POP3 Carriage Return + Line Feed
*/
public $CRLF = "\r\n";
/**
* POP3 Mail Server
* @var string
*/
public $host;
/**
* @var int Debug display level
* Options: 0 = no, 1+ = yes
*/
public $do_debug = 0;
/**
* POP3 Port
* @var int
*/
public $port;
/**
* @var string POP3 mail Server
*/
public $host;
/**
* POP3 Timeout Value
* @var int
*/
public $tval;
/**
* @var int POP3 Port number
*/
public $port;
/**
* POP3 Username
* @var string
*/
public $username;
/**
* @var int POP3 Timeout Value in seconds
*/
public $tval;
/**
* POP3 Password
* @var string
*/
public $password;
/**
* @var string POP3 Username
*/
public $username;
/**
* Sets the POP3 PHPMailer Version number
* @var string
*/
public $Version = '5.2.6';
/**
* @var string POP3 Password
*/
public $password;
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
/**
* @var resource Resource handle for the POP connection socket
*/
private $pop_conn;
/**
* @var resource Resource handle for the POP connection socket
*/
private $pop_conn;
/**
* @var boolean Are we connected?
*/
private $connected;
/**
* @var array Error container
*/
private $error; // Error log array
/**
* @var bool Are we connected?
*/
private $connected;
/**
* Constructor, sets the initial values
* @access public
* @return POP3
*/
public function __construct() {
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}
/**
* @var array Error container
*/
private $error; // Error log array
/**
* Combination of public events - connect, login, disconnect
* @access public
* @param string $host
* @param bool|int $port
* @param bool|int $tval
* @param string $username
* @param string $password
* @param int $debug_level
* @return bool
*/
public function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) {
$this->host = $host;
// If no port value is passed, retrieve it
if ($port == false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
/**
* Constructor
* @access public
*/
public function __construct()
{
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}
// If no port value is passed, retrieve it
if ($tval == false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
/**
* Combination of public events - connect, login, disconnect
* @access public
* @param string $host
* @param bool|int $port
* @param bool|int $tval
* @param string $username
* @param string $password
* @param int $debug_level
* @return bool
*/
public function authorise($host, $port = false, $tval = false, $username = '', $password = '', $debug_level = 0)
{
$this->host = $host;
// If no port value is passed, retrieve it
if ($port == false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
}
// If no port value is passed, retrieve it
if ($tval == false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Refresh the error log
$this->error = null;
// connect
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->login($this->username, $this->password);
if ($login_result) {
$this->disconnect();
return true;
}
}
// We need to disconnect regardless if the login succeeded
$this->disconnect();
return false;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
/**
* Connect to the POP3 server
* @access public
* @param string $host
* @param bool|int $port
* @param integer $tval
* @return boolean
*/
public function connect($host, $port = false, $tval = 30)
{
// Are we already connected?
if ($this->connected) {
return true;
}
// Refresh the error log
$this->error = null;
//On Windows this will raise a PHP Warning error if the hostname doesn't exist.
//Rather than suppress it with @fsockopen, capture it cleanly instead
set_error_handler(array(&$this, 'catchWarning'));
// Connect
$result = $this->Connect($this->host, $this->port, $this->tval);
// connect to the POP3 server
$this->pop_conn = fsockopen(
$host, // POP3 Host
$port, // Port #
$errno, // Error Number
$errstr, // Error Message
$tval
); // Timeout (seconds)
// Restore the error handler
restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
}
// Did we connect?
if ($this->pop_conn == false) {
// It would appear not...
$this->error = array(
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
}
if ($result) {
$login_result = $this->Login($this->username, $this->password);
if ($login_result) {
$this->Disconnect();
return true;
}
// Increase the stream time-out
// Check for PHP 4.3.0 or later
if (version_compare(phpversion(), '5.0.0', 'ge')) {
stream_set_timeout($this->pop_conn, $tval, 0);
} else {
// Does not work on Windows
if (substr(PHP_OS, 0, 3) !== 'WIN') {
socket_set_timeout($this->pop_conn, $tval, 0);
}
}
// Get the POP3 server response
$pop3_response = $this->getResponse();
// Check for the +OK
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking
$this->connected = true;
return true;
}
return false;
}
// We need to disconnect regardless if the login succeeded
$this->Disconnect();
/**
* login to the POP3 server (does not support APOP yet)
* @access public
* @param string $username
* @param string $password
* @return boolean
*/
public function login($username = '', $password = '')
{
if ($this->connected == false) {
$this->error = 'Not connected to POP3 server';
return false;
}
/**
* Connect to the POP3 server
* @access public
* @param string $host
* @param bool|int $port
* @param integer $tval
* @return boolean
*/
public function Connect ($host, $port = false, $tval = 30) {
// Are we already connected?
if ($this->connected) {
return true;
if ($this->do_debug >= 1) {
$this->displayErrors();
}
}
if (empty($username)) {
$username = $this->username;
}
if (empty($password)) {
$password = $this->password;
}
$pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF;
// send the Username
$this->sendString($pop_username);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
// send the Password
$this->sendString($pop_password);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
}
}
return false;
}
/*
On Windows this will raise a PHP Warning error if the hostname doesn't exist.
Rather than suppress it with @fsockopen, let's capture it cleanly instead
*/
set_error_handler(array(&$this, 'catchWarning'));
// Connect to the POP3 server
$this->pop_conn = fsockopen($host, // POP3 Host
$port, // Port #
$errno, // Error Number
$errstr, // Error Message
$tval); // Timeout (seconds)
// Restore the error handler
restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
/**
* disconnect from the POP3 server
* @access public
*/
public function disconnect()
{
$this->sendString('QUIT');
fclose($this->pop_conn);
}
// Did we connect?
if ($this->pop_conn == false) {
// It would appear not...
$this->error = array(
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
/**
* Get the socket response back.
* $size is the maximum number of bytes to retrieve
* @access private
* @param integer $size
* @return string
*/
private function getResponse($size = 128)
{
$pop3_response = fgets($this->pop_conn, $size);
return $pop3_response;
}
// Increase the stream time-out
// Check for PHP 4.3.0 or later
if (version_compare(phpversion(), '5.0.0', 'ge')) {
stream_set_timeout($this->pop_conn, $tval, 0);
} else {
// Does not work on Windows
if (substr(PHP_OS, 0, 3) !== 'WIN') {
socket_set_timeout($this->pop_conn, $tval, 0);
}
/**
* send a string down the open socket connection to the POP3 server
* @access private
* @param string $string
* @return integer
*/
private function sendString($string)
{
$bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
return $bytes_sent;
}
// Get the POP3 server response
$pop3_response = $this->getResponse();
// Check for the +OK
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking
$this->connected = true;
return true;
}
return false;
}
/**
* Login to the POP3 server (does not support APOP yet)
* @access public
* @param string $username
* @param string $password
* @return boolean
*/
public function Login ($username = '', $password = '') {
if ($this->connected == false) {
$this->error = 'Not connected to POP3 server';
if ($this->do_debug >= 1) {
$this->displayErrors();
}
/**
* Checks the POP3 server response for +OK or -ERR
* @access private
* @param string $string
* @return boolean
*/
private function checkResponse($string)
{
if (substr($string, 0, 3) !== '+OK') {
$this->error = array(
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
} else {
return true;
}
}
if (empty($username)) {
$username = $this->username;
/**
* If debug is enabled, display the error message array
* @access private
*/
private function displayErrors()
{
echo '<pre>';
foreach ($this->error as $single_error) {
print_r($single_error);
}
echo '</pre>';
}
if (empty($password)) {
$password = $this->password;
/**
* Takes over from PHP for the socket warning handler
* @access private
* @param integer $errno
* @param string $errstr
* @param string $errfile
* @param integer $errline
*/
private function catchWarning($errno, $errstr, $errfile, $errline)
{
$this->error[] = array(
'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno,
'errstr' => $errstr,
'errfile' => $errfile,
'errline' => $errline
);
}
$pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF;
// Send the Username
$this->sendString($pop_username);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
// Send the Password
$this->sendString($pop_password);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
}
}
return false;
}
/**
* Disconnect from the POP3 server
* @access public
*/
public function Disconnect () {
$this->sendString('QUIT');
fclose($this->pop_conn);
}
/////////////////////////////////////////////////
// Private Methods
/////////////////////////////////////////////////
/**
* Get the socket response back.
* $size is the maximum number of bytes to retrieve
* @access private
* @param integer $size
* @return string
*/
private function getResponse ($size = 128) {
$pop3_response = fgets($this->pop_conn, $size);
return $pop3_response;
}
/**
* Send a string down the open socket connection to the POP3 server
* @access private
* @param string $string
* @return integer
*/
private function sendString ($string) {
$bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
return $bytes_sent;
}
/**
* Checks the POP3 server response for +OK or -ERR
* @access private
* @param string $string
* @return boolean
*/
private function checkResponse ($string) {
if (substr($string, 0, 3) !== '+OK') {
$this->error = array(
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
} else {
return true;
}
}
/**
* If debug is enabled, display the error message array
* @access private
*/
private function displayErrors () {
echo '<pre>';
foreach ($this->error as $single_error) {
print_r($single_error);
}
echo '</pre>';
}
/**
* Takes over from PHP for the socket warning handler
* @access private
* @param integer $errno
* @param string $errstr
* @param string $errfile
* @param integer $errline
*/
private function catchWarning ($errno, $errstr, $errfile, $errline) {
$this->error[] = array(
'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno,
'errstr' => $errstr
);
}
// End of class
}

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,8 @@
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:
If you are having problems connecting or sending emails through your SMTP server, the SMTP class can provide more information about the processing/errors taking place.
Use the debug functionality of the class to see what's going on in your connections. To do that, set the debug level in your script. For example:
$mail->SMTPDebug = 1;
$mail->IsSMTP(); // telling the class to use SMTP
$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
@ -12,12 +10,8 @@ $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
$mail->SMTPDebug = 0; ... will disable debugging (you can also leave this out completely, 0 is the default)
$mail->SMTPDebug = 1; ... will echo errors and server responses
$mail->SMTPDebug = 2; ... will echo errors, server responses and client messages
And finally, don't forget to disable debugging before going into production.
Enjoy!
Andy

View File

@ -27,8 +27,8 @@ $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);
$query<EFBFBD> =<3D>"SELECT full_name, email,<2C>photo<74>FROM employee<65>WHERE<52>id=$id";
$result<EFBFBD>=<3D>@MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result))
{
@ -46,15 +46,15 @@ while ($row = mysql_fetch_array ($result))
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
$mail->addAddress($row["email"], $row["full_name"]);
$mail->addStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send())
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();
$mail->clearAddresses();
$mail->clearAttachments();
}
</pre>
</td>
@ -90,7 +90,7 @@ class my_phpmailer extends phpmailer {
var $From = "from@example.com";
var $FromName = "Mailer";
var $Host = "smtp1.example.com;smtp2.example.com";
var $Mailer = "smtp"; // Alternative to IsSMTP()
var $Mailer = "smtp"; // Alternative to isSMTP()
var $WordWrap = 75;
// Replace the default error_handler
@ -106,15 +106,14 @@ class my_phpmailer extends phpmailer {
// Place your new code here
}
}
</pre>
</td>
</tr>
</table>
<br>
Now here's a normal PHP page in the site, which will have all the defaults set
above:<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>
@ -126,12 +125,12 @@ require("mail.inc.php");
$mail = new my_phpmailer;
// Now you only need to add the necessary stuff
$mail->AddAddress("josh@example.com", "Josh Adams");
$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
$mail->addAttachment("c:/temp/11-10-00.zip", "new_name.zip"); // optional name
if(!$mail->Send())
if(!$mail->send())
{
echo "There was an error sending the message";
exit;
@ -142,7 +141,5 @@ echo "Message was sent successfully";
</td>
</tr>
</table>
</p>
</body>
</html>

View File

@ -1,20 +1,33 @@
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]
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 directory.
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.
<?php
$pop->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;
}
?>
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]
The authorise parameters are as follows:
$pop->authorise('pop3.example.com', 110, 30, 'mailer', 'password', 1);
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)
@ -34,6 +47,4 @@ Final Comments + the Download
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)

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - Exceptions test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - Exceptions test</title>
</head>
<body>
<?php
@ -12,29 +12,29 @@ require '../class.phpmailer.php';
//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'), dirname(__FILE__));
//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.gif');
//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!";
//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'), dirname(__FILE__));
//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.gif');
//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 (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
</body>

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - GMail SMTP test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - GMail SMTP test</title>
</head>
<body>
<?php
@ -16,46 +16,47 @@ require '../class.phpmailer.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username@gmail.com";
$mail->Username = "username@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->SetFrom('from@example.com', 'First Last');
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->AddReplyTo('replyto@example.com','First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress('whoto@example.com', 'John Doe');
$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'), dirname(__FILE__));
//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'), dirname(__FILE__));
//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.gif');
$mail->addAttachment('images/phpmailer_mini.gif');
//Send the message, check for errors
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
echo "Message sent!";
}
?>
</body>

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - mail() test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - mail() test</title>
</head>
<body>
<?php
@ -11,25 +11,26 @@ require '../class.phpmailer.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');
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->AddReplyTo('replyto@example.com','First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress('whoto@example.com', 'John Doe');
$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'), dirname(__FILE__));
//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'), dirname(__FILE__));
//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.gif');
$mail->addAttachment('images/phpmailer_mini.gif');
//Send the message, check for errors
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
echo "Message sent!";
}
?>
</body>

View File

@ -1,49 +1,51 @@
<?php
error_reporting(E_STRICT|E_ALL);
error_reporting(E_STRICT | E_ALL);
date_default_timezone_set('Etc/UTC');
require '../class.phpmailer.php';
$mail = new PHPMailer();
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$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->Host = 'mail.example.com';
$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->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->Host = 'mail.example.com';
$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";
$mail->Subject = "PHPMailer Simple database mailing list test";
//Connect to the database and select the recipients from your mailing list that have not yet been sent to
//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 = mysql_connect('localhost', 'username', 'password');
mysql_select_db('mydb', $mysql);
$result = mysql_query("SELECT full_name, email, photo FROM mailinglist WHERE sent = false", $mysql);
while ($row = mysql_fetch_array($result)) {
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML($body);
$mail->AddAddress($row['email'], $row['full_name']);
$mail->AddStringAttachment($row['photo'], 'YourPhoto.jpg'); //Assumes the image data is stored in the DB
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->msgHTML($body);
$mail->addAddress($row['email'], $row['full_name']);
$mail->addStringAttachment($row['photo'], 'YourPhoto.jpg'); //Assumes the image data is stored in the DB
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
break; //Abandon sending
} else {
echo "Message sent to :" . $row['full_name'] . ' (' . str_replace("@", "&#64;", $row['email']) . ')<br />';
//Mark it as sent in the DB
mysql_query("UPDATE mailinglist SET sent = true WHERE email = '".mysql_real_escape_string($row['email'], $mysql)."'");
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
if (!$mail->send()) {
echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
break; //Abandon sending
} else {
echo "Message sent to :" . $row['full_name'] . ' (' . str_replace("@", "&#64;", $row['email']) . ')<br />';
//Mark it as sent in the DB
mysql_query(
"UPDATE mailinglist SET sent = true WHERE email = '" . mysql_real_escape_string($row['email'], $mysql) . "'"
);
}
// Clear all addresses and attachments for next loop
$mail->clearAddresses();
$mail->clearAttachments();
}

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - POP-before-SMTP test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - POP-before-SMTP test</title>
</head>
<body>
<?php
@ -11,8 +11,8 @@ require '../class.pop3.php';
//Create a new POP client instance
$pop = new POP3();
//Authenticate via POP
$pop->Authorise('pop3.yourdomain.com', 110, 30, 'username', 'password', 1);
//authenticate via POP
$pop->authorise('pop3.yourdomain.com', 110, 30, 'username', 'password', 1);
//Now you should be clear to submit messages over SMTP for a while
//Only applies if your host supports POP-before-SMTP
@ -20,43 +20,43 @@ $pop->Authorise('pop3.yourdomain.com', 110, 30, 'username', 'password', 1);
//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;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//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'), dirname(__FILE__));
//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.gif');
//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!";
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//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'), dirname(__FILE__));
//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.gif');
//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 (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
</body>

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - sendmail test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - sendmail test</title>
</head>
<body>
<?php
@ -11,27 +11,28 @@ require '../class.phpmailer.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
// Set PHPMailer to use the sendmail transport
$mail->IsSendmail();
$mail->isSendmail();
//Set who the message is to be sent from
$mail->SetFrom('from@example.com', 'First Last');
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->AddReplyTo('replyto@example.com','First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress('whoto@example.com', 'John Doe');
$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'), dirname(__FILE__));
//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'), dirname(__FILE__));
//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.gif');
$mail->addAttachment('images/phpmailer_mini.gif');
//Send the message, check for errors
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
echo "Message sent!";
}
?>
</body>

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - SMTP test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - SMTP test</title>
</head>
<body>
<?php
@ -16,44 +16,45 @@ require '../class.phpmailer.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.example.com";
$mail->Host = "mail.example.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "yourname@example.com";
$mail->Username = "yourname@example.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->SetFrom('from@example.com', 'First Last');
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->AddReplyTo('replyto@example.com','First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress('whoto@example.com', 'John Doe');
$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'), dirname(__FILE__));
//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'), dirname(__FILE__));
//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.gif');
$mail->addAttachment('images/phpmailer_mini.gif');
//Send the message, check for errors
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
echo "Message sent!";
}
?>
</body>

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - SMTP without auth test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - SMTP without auth test</title>
</head>
<body>
<?php
@ -16,40 +16,41 @@ require_once '../class.phpmailer.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.example.com";
$mail->Host = "mail.example.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = false;
$mail->SMTPAuth = false;
//Set who the message is to be sent from
$mail->SetFrom('from@example.com', 'First Last');
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->AddReplyTo('replyto@example.com','First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress('whoto@example.com', 'John Doe');
$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'), dirname(__FILE__));
//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'), dirname(__FILE__));
//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.gif');
$mail->addAttachment('images/phpmailer_mini.gif');
//Send the message, check for errors
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
echo "Message sent!";
}
?>
</body>

View File

@ -8,17 +8,17 @@ $PHPMAILER_LANG['authenticate'] = 'Erreur SMTP : échec de l\'authentif
$PHPMAILER_LANG['connect_host'] = 'Erreur SMTP : impossible de se connecter au serveur SMTP.';
$PHPMAILER_LANG['data_not_accepted'] = 'Erreur SMTP : données incorrectes.';
$PHPMAILER_LANG['empty_message'] = 'Corps de message vide.';
$PHPMAILER_LANG['encoding'] = 'Encodage inconnu: ';
$PHPMAILER_LANG['execute'] = 'Impossible de lancer l\'exécution: ';
$PHPMAILER_LANG['file_access'] = 'Impossible d\'accéder au fichier: ';
$PHPMAILER_LANG['encoding'] = 'Encodage inconnu : ';
$PHPMAILER_LANG['execute'] = 'Impossible de lancer l\'exécution : ';
$PHPMAILER_LANG['file_access'] = 'Impossible d\'accéder au fichier : ';
$PHPMAILER_LANG['file_open'] = 'Erreur de fichier : ouverture impossible: ';
$PHPMAILER_LANG['from_failed'] = 'L\'adresse d\'expéditeur suivante a échouée: ';
$PHPMAILER_LANG['from_failed'] = 'L\'adresse d\'expéditeur suivante a échouée : ';
$PHPMAILER_LANG['instantiate'] = 'Impossible d\'instancier la fonction mail.';
$PHPMAILER_LANG['invalid_address'] = 'L\'adresse courriel n\'est pas valide: ';
$PHPMAILER_LANG['invalid_address'] = 'L\'adresse courriel n\'est pas valide : ';
$PHPMAILER_LANG['mailer_not_supported'] = ' client de messagerie non supporté.';
$PHPMAILER_LANG['provide_address'] = 'Vous devez fournir au moins une adresse de destinataire.';
$PHPMAILER_LANG['recipients_failed'] = 'Erreur SMTP : les destinataires suivants sont en erreur: ';
$PHPMAILER_LANG['signing'] = 'Erreur de signature: ';
$PHPMAILER_LANG['recipients_failed'] = 'Erreur SMTP : les destinataires suivants sont en erreur : ';
$PHPMAILER_LANG['signing'] = 'Erreur de signature : ';
$PHPMAILER_LANG['smtp_connect_failed'] = 'Échec de la connexion SMTP.';
$PHPMAILER_LANG['smtp_error'] = 'Erreur du serveur SMTP: ';
$PHPMAILER_LANG['variable_set'] = 'Ne peut initialiser ou réinitialiser une variable: ';
$PHPMAILER_LANG['smtp_error'] = 'Erreur du serveur SMTP : ';
$PHPMAILER_LANG['variable_set'] = 'Ne peut initialiser ou réinitialiser une variable : ';

View File

@ -18,7 +18,7 @@ require 'PHPUnit/Autoload.php';
* PHPMailer - PHP email transport unit test class
* Performs authentication tests
*/
class phpmailerLangTest extends PHPUnit_Framework_TestCase
class PHPMailerLangTest extends PHPUnit_Framework_TestCase
{
/**
* Holds the default phpmailer instance.
@ -56,7 +56,7 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
/**
* Run before each test is started.
*/
function setUp()
public function setUp()
{
if (file_exists('./testbootstrap.php')) {
@ -94,7 +94,7 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
$this->Mail->Username = "";
$this->Mail->Password = "";
$this->Mail->PluginDir = $this->INCLUDE_DIR;
$this->Mail->AddReplyTo("no_reply@phpmailer.example.com", "Reply Guy");
$this->Mail->addReplyTo("no_reply@phpmailer.example.com", "Reply Guy");
$this->Mail->Sender = "unit_test@phpmailer.example.com";
if (strlen($this->Mail->Host) > 0) {
@ -105,17 +105,17 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
}
if (array_key_exists('mail_to', $_REQUEST)) {
$this->SetAddress($_REQUEST['mail_to'], 'Test User', 'to');
$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');
$this->setAddress($_REQUEST['mail_cc'], 'Carbon User', 'cc');
}
}
/**
* Run after each test is completed.
*/
function tearDown()
public function tearDown()
{
// Clean global variables
$this->Mail = null;
@ -129,7 +129,7 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
* @private
* @returns void
*/
function BuildBody()
public function buildBody()
{
$this->CheckChanges();
@ -159,7 +159,7 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
}
// If attachments then create an attachment list
$attachments = $this->Mail->GetAttachments();
$attachments = $this->Mail->getAttachments();
if (count($attachments) > 0) {
$ReportBody .= "Attachments:" . $eol;
$ReportBody .= $bullet_start;
@ -205,34 +205,34 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
* @private
* @returns void
*/
function CheckChanges()
public function checkChanges()
{
if ($this->Mail->Priority != 3) {
$this->AddChange("Priority", $this->Mail->Priority);
$this->addChange("Priority", $this->Mail->Priority);
}
if ($this->Mail->Encoding != "8bit") {
$this->AddChange("Encoding", $this->Mail->Encoding);
$this->addChange("Encoding", $this->Mail->Encoding);
}
if ($this->Mail->CharSet != "iso-8859-1") {
$this->AddChange("CharSet", $this->Mail->CharSet);
$this->addChange("CharSet", $this->Mail->CharSet);
}
if ($this->Mail->Sender != "") {
$this->AddChange("Sender", $this->Mail->Sender);
$this->addChange("Sender", $this->Mail->Sender);
}
if ($this->Mail->WordWrap != 0) {
$this->AddChange("WordWrap", $this->Mail->WordWrap);
$this->addChange("WordWrap", $this->Mail->WordWrap);
}
if ($this->Mail->Mailer != "mail") {
$this->AddChange("Mailer", $this->Mail->Mailer);
$this->addChange("Mailer", $this->Mail->Mailer);
}
if ($this->Mail->Port != 25) {
$this->AddChange("Port", $this->Mail->Port);
$this->addChange("Port", $this->Mail->Port);
}
if ($this->Mail->Helo != "localhost.localdomain") {
$this->AddChange("Helo", $this->Mail->Helo);
$this->addChange("Helo", $this->Mail->Helo);
}
if ($this->Mail->SMTPAuth) {
$this->AddChange("SMTPAuth", "true");
$this->addChange("SMTPAuth", "true");
}
}
@ -243,7 +243,7 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
* @param string $sNewValue
* @return void
*/
function AddChange($sName, $sNewValue)
public function addChange($sName, $sNewValue)
{
$this->ChangeLog[] = array($sName, $sNewValue);
}
@ -254,7 +254,7 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
* @param string $sValue
* @return void
*/
function AddNote($sValue)
public function addNote($sValue)
{
$this->NoteLog[] = $sValue;
}
@ -267,31 +267,27 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
* @param string $sType
* @return boolean
*/
function SetAddress($sAddress, $sName = '', $sType = 'to')
public function setAddress($sAddress, $sName = '', $sType = 'to')
{
switch ($sType) {
case 'to':
return $this->Mail->AddAddress($sAddress, $sName);
return $this->Mail->addAddress($sAddress, $sName);
case 'cc':
return $this->Mail->AddCC($sAddress, $sName);
return $this->Mail->addCC($sAddress, $sName);
case "bcc":
return $this->Mail->AddBCC($sAddress, $sName);
return $this->Mail->addBCC($sAddress, $sName);
}
return false;
}
/////////////////////////////////////////////////
// UNIT TESTS
/////////////////////////////////////////////////
/**
* Test language files for missing and excess translations
* All languages are compared with English
*/
function test_Translations()
public function testTranslations()
{
$this->Mail->SetLanguage('en');
$definedStrings = $this->Mail->GetTranslations();
$this->Mail->setLanguage('en');
$definedStrings = $this->Mail->getTranslations();
$err = '';
foreach (new DirectoryIterator('../language') as $fileInfo) {
if ($fileInfo->isDot()) {
@ -321,24 +317,24 @@ class phpmailerLangTest extends PHPUnit_Framework_TestCase
* 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>
* <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>
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>PHPMailer Lite - DKIM and Callback Function test</title>
<title>PHPMailer Lite - DKIM and Callback Function test</title>
</head>
<body>
@ -18,58 +18,63 @@
* 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;
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 . "\n\n". $body . "\n";
return true;
}
require_once '../class.phpmailer.php';
$mail = new PHPMailer();
try {
$mail->IsMail();
$mail->SetFrom('you@example.com', 'Your Name');
$mail->AddAddress('another@example.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('../examples/contents.html'));
$mail->AddAttachment('../examples/images/phpmailer.png'); // attachment
$mail->AddAttachment('../examples/images/phpmailer_mini.gif'); // attachment
$mail->action_function = 'callbackAction';
$mail->Send();
echo "Message Sent OK</p>\n";
$mail->isMail();
$mail->setFrom('you@example.com', 'Your Name');
$mail->addAddress('another@example.com', 'John Doe');
$mail->Subject = 'PHPMailer Lite Test Subject via mail()';
// optional - msgHTML will create an alternate automatically
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->msgHTML(file_get_contents('../examples/contents.html'));
$mail->addAttachment('../examples/images/phpmailer.png'); // attachment
$mail->addAttachment('../examples/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
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
echo $e->getMessage(); //Boring error messages from anything else!
}
function cleanEmails($str,$type) {
if ($type == 'cc') {
$addy['Email'] = $str[0];
$addy['Name'] = $str[1];
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;
}
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;
}
?>