Giter Site home page Giter Site logo

phpmailer / phpmailer Goto Github PK

View Code? Open in Web Editor NEW
20.6K 885.0 9.7K 19.01 MB

The classic email sending library for PHP

License: GNU Lesser General Public License v2.1

PHP 99.44% Shell 0.56%
php smtp php-library email xoauth2 tls-support phpmailer attachment hacktoberfest

phpmailer's Introduction

SWUbanner

PHPMailer

PHPMailer – A full-featured email creation and transfer class for PHP

Test status codecov.io Latest Stable Version Total Downloads License API Docs OpenSSF Scorecard

Features

  • Probably the world's most popular code for sending email from PHP!
  • Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
  • Integrated SMTP support – send without a local mail server
  • Send emails with multiple To, CC, BCC, and Reply-to addresses
  • Multipart/alternative emails for mail clients that do not read HTML email
  • Add attachments, including inline
  • Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
  • SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over SMTPS and SMTP+STARTTLS transports
  • Validates email addresses automatically
  • Protects against header injection attacks
  • Error messages in over 50 languages!
  • DKIM and S/MIME signing support
  • Compatible with PHP 5.5 and later, including PHP 8.2
  • Namespaced to prevent name clashes
  • Much more!

Why you might need it

Many PHP developers need to send email from their code. The only PHP function that supports this directly is mail(). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments.

Formatting email correctly is surprisingly difficult. There are myriad overlapping (and conflicting) standards, requiring tight adherence to horribly complicated formatting and encoding rules – the vast majority of code that you'll find online that uses the mail() function directly is just plain wrong, if not unsafe!

The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD, and macOS platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP client allows email sending on all platforms without needing a local mail server. Be aware though, that the mail() function should be avoided when possible; it's both faster and safer to use SMTP to localhost.

Please don't be tempted to do it yourself – if you don't use PHPMailer, there are many other excellent libraries that you should look at before rolling your own. Try SwiftMailer , Laminas/Mail, ZetaComponents, etc.

License

This software is distributed under the LGPL 2.1 license, along with the GPL Cooperation Commitment. Please read LICENSE for information on the software availability and distribution.

Installation & loading

PHPMailer is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install PHPMailer. Just add this line to your composer.json file:

"phpmailer/phpmailer": "^6.9.1"

or run

composer require phpmailer/phpmailer

Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of PHPMailer.

If you want to use XOAUTH2 authentication, you will also need to add a dependency on the league/oauth2-client and appropriate service adapters package in your composer.json, or take a look at by @decomplexity's SendOauth2 wrapper, especially if you're using Microsoft services.

Alternatively, if you're not using Composer, you can download PHPMailer as a zip file, (note that docs and examples are not included in the zip file), then copy the contents of the PHPMailer folder into one of the include_path directories specified in your PHP configuration and load each class file manually:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

If you're not using the SMTP class explicitly (you're probably not), you don't need a use line for the SMTP class. Even if you're not using exceptions, you do still need to load the Exception class as it is used internally.

Legacy versions

PHPMailer 5.2 (which is compatible with PHP 5.0 — 7.0) is no longer supported, even for security updates. You will find the latest version of 5.2 in the 5.2-stable branch. If you're using PHP 5.5 or later (which you should be), switch to the 6.x releases.

Upgrading from 5.2

The biggest changes are that source files are now in the src/ folder, and PHPMailer now declares the namespace PHPMailer\PHPMailer. This has several important effects – read the upgrade guide for more details.

Minimal installation

While installing the entire package manually or with Composer is simple, convenient, and reliable, you may want to include only vital files in your project. At the very least you will need src/PHPMailer.php. If you're using SMTP, you'll need src/SMTP.php, and if you're using POP-before SMTP (very unlikely!), you'll need src/POP3.php. You can skip the language folder if you're not showing errors to users and can make do with English-only errors. If you're using XOAUTH2 you will need src/OAuth.php as well as the Composer dependencies for the services you wish to authenticate with. Really, it's much easier to use Composer!

A Simple Example

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'smtp.example.com';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = '[email protected]';                     //SMTP username
    $mail->Password   = 'secret';                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
    $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     //Add a recipient
    $mail->addAddress('[email protected]');               //Name is optional
    $mail->addReplyTo('[email protected]', 'Information');
    $mail->addCC('[email protected]');
    $mail->addBCC('[email protected]');

    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

You'll find plenty to play with in the examples folder, which covers many common scenarios including sending through Gmail, building contact forms, sending to mailing lists, and more.

If you are re-using the instance (e.g. when sending to a mailing list), you may need to clear the recipient list to avoid sending duplicate messages. See the mailing list example for further guidance.

That's it. You should now be ready to use PHPMailer!

Localization

PHPMailer defaults to English, but in the language folder, you'll find many translations for PHPMailer error messages that you may encounter. Their filenames contain ISO 639-1 language code for the translations, for example fr for French. To specify a language, you need to tell PHPMailer which one to use, like this:

//To load the French version
$mail->setLanguage('fr', '/optional/path/to/language/directory/');

We welcome corrections and new languages – if you're looking for corrections, run the Language/TranslationCompletenessTest.php script in the tests folder and it will show any missing translations.

Documentation

Start reading at the GitHub wiki. If you're having trouble, head for the troubleshooting guide as it's frequently updated.

Examples of how to use PHPMailer for common scenarios can be found in the examples folder. If you're looking for a good starting point, we recommend you start with the Gmail example.

To reduce PHPMailer's deployed code footprint, examples are not included if you load PHPMailer via Composer or via GitHub's zip file download, so you'll need to either clone the git repository or use the above links to get to the examples directly.

Complete generated API documentation is available online.

You can generate complete API-level documentation by running phpdoc in the top-level folder, and documentation will appear in the docs folder, though you'll need to have PHPDocumentor installed. You may find the unit tests a good reference for how to do various operations such as encryption.

If the documentation doesn't cover what you need, search the many questions on Stack Overflow, and before you ask a question about "SMTP Error: Could not connect to SMTP host.", read the troubleshooting guide.

Tests

PHPMailer tests use PHPUnit 9, with a polyfill to let 9-style tests run on older PHPUnit and PHP versions.

Test status

If this isn't passing, is there something you can do to help?

Security

Please disclose any vulnerabilities found responsibly – report security issues to the maintainers privately.

See SECURITY and PHPMailer's security advisories on GitHub.

Contributing

Please submit bug reports, suggestions, and pull requests to the GitHub issue tracker.

We're particularly interested in fixing edge cases, expanding test coverage, and updating translations.

If you found a mistake in the docs, or want to add something, go ahead and amend the wiki – anyone can edit it.

If you have git clones from prior to the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:

git remote set-url upstream https://github.com/PHPMailer/PHPMailer.git

Please don't use the SourceForge or Google Code projects any more; they are obsolete and no longer maintained.

Sponsorship

Development time and resources for PHPMailer are provided by Smartmessages.net, the world's only privacy-first email marketing system.

Smartmessages.net privacy-first email marketing logo

Donations are very welcome, whether in beer 🍺, T-shirts 👕, or cold, hard cash 💰. Sponsorship through GitHub is a simple and convenient way to say "thank you" to PHPMailer's maintainers and contributors – just click the "Sponsor" button on the project page. If your company uses PHPMailer, consider taking part in Tidelift's enterprise support programme.

PHPMailer For Enterprise

Available as part of the Tidelift Subscription.

The maintainers of PHPMailer and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open-source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. Learn more.

Changelog

See changelog.

History

  • PHPMailer was originally written in 2001 by Brent R. Matzelle as a SourceForge project.
  • Marcus Bointon (coolbru on SF) and Andy Prevost (codeworxtech) took over the project in 2004.
  • Became an Apache incubator project on Google Code in 2010, managed by Jim Jagielski.
  • Marcus created his fork on GitHub in 2008.
  • Jim and Marcus decide to join forces and use GitHub as the canonical and official repo for PHPMailer in 2013.
  • PHPMailer moves to the PHPMailer organisation on GitHub in 2013.

What's changed since moving from SourceForge?

  • Official successor to the SourceForge and Google Code projects.
  • Test suite.
  • Continuous integration with GitHub Actions.
  • Composer support.
  • Public development.
  • Additional languages and language strings.
  • CRAM-MD5 authentication support.
  • Preserves full repo history of authors, commits, and branches from the original SourceForge project.

phpmailer's People

Contributors

aflorea avatar arisophy avatar ayesh avatar blazorazem avatar campbell-m avatar czirkoszoltan avatar decomplexity avatar dependabot[bot] avatar fbonzon avatar fonata avatar glensc avatar heronman avatar hrvoj3e avatar jayantisuthar avatar jimjag avatar jrfnl avatar mathiasreker avatar mhm5000 avatar miken32 avatar mrbellek avatar msturdy avatar royopa avatar sabas avatar sherryl4george avatar sinteur avatar slamdunk avatar synchro avatar voronkovich avatar vuthao avatar wf-frank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpmailer's Issues

Email Syntax Validator

I would like to see a helper function that validates a email address before attempting to send a message.

PHPMailer currently fails to send to addresses that contain "(" '"' and " ", as claimed to be valid on Wikipedia http://en.wikipedia.org/wiki/Email_address#Valid_email_addresses

So The following 'vaild' examples don't work
(Comment)[email protected]
My."FunkyText"[email protected]
Ihavea"[email protected]
My SPACY [email protected]

Yes Wikipedia can be wrong, but in any-case I would like to pre-validate that an address is syntactically correct before making a class instance.

Images wrongly attached to the mail

Hi
I've noticed on the last commit, that now inline images base64 encoded are wrongly attached to my mails, as before they were embedded.

Result before the change (open and close tags omitted for the cid lines):

--b2_66908324beade643ef61833062a95135
Content-Type: image/jpeg; name="E_maging_Compute_4e1573014c224.jpg"
Content-Transfer-Encoding: base64
Content-ID: vendor_image
Content-Disposition: inline; filename="E_maging_Compute_4e1573014c224.jpg"

Result with the new commits:

--b2_4c18b756c600578cfb921d1e3123e7c0
Content-Type: image/jpeg; name="E_maging_Compute_4e1573014c224.jpg"
Content-Transfer-Encoding: base64
Content-ID: [email protected]
Content-Disposition: inline; filename=E_maging_Compute_4e1573014c224.jpg

The "cid:" call of the image is the same for both source mail.
But in the second case, the image is broken and just attached to the mail (wrongly)
Line 2493 in class.phpmailer.php could be the one.

I don't know if the lacks of quotes could have an influence on that. Not yet test that point.
Anyway it's an RFC recomend so...

Thanks for the work ;)

MsgHTML() and IsHTML() + Body fail silently without enclosing HTML and BODY tags

Hi folks,

I've noticed that both

$mail->MsgHTML($body);

and

$mail->IsHTML(true);
$mail->Body = $body;

will fail to send an email without throwing an error if $body does not begin and end with the appropriate HTML and BODY tags. I'm not sure if this is a bug or if it should be a requested feature (or if I should just format my HTML emails appropriately), but I've seen a few people trying to figure out what's going on, so I thought I'd throw it out there.

Thanks!

Add a way to see the email without actually sending it?

I've just written a program with some complex requirements for choosing recipients for emails. During development, I would have liked a way to output the headers and body of the email without actually sending it, in order to confirm that it is correctly configured.

They way I've done this so far is to first build up an array, which I can easily inspect, and then use that to configure the PHPMailer object.

Is there a way to do this with PHPMailer? If not, I think it would be a good feature.

VERP support problem

When instantiating SMTP object, the latest doesn't receive the value of the do_verp variable, and it is not possible to use XVERP extension on the corresponding SMTP server.

It can be fixed by inserting on line 1062 in class.phpmailer.php the following line:

$this->smtp->do_verp = $this->do_verp;

Problem with date in RFCDate

If i leave te default date format, i get twice +100

This : $result = sprintf("%s %s%04d", date('D, j M Y H:i:s O'), $tzs, $tz);
Gives in logs : CLIENT -> SMTP: Date: Thu, 28 Mar 2013 11:18:13 +0100 +0100

So i changed it to : $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
(deleted the O option in date function)

MsgHTML() does not recreate AltBody

MsgHTML() always overwrites the value of Body, but if AltBody has already been set to a non-empty value, it's left untouched. This doesn't make sense when AltBody is populated by MsgHTML if it is initially empty, meaning that subsequent calls to MsgHTML will change Body but not AltBody. This is probably unexpected if you're creating and sending messages in a loop. If you want AltBody to be kept, it's simple to set it after calling MsgHTML, or simply don't use MsgHTML in the first place. The whole point of MsgHTML is to make message setup simpler, so it should overwrite AltBody every time.

This issue was originally reported on sourceforge by Thilo Muller.

Retrieve the message ID

Hi,

Is it possible at all to retrieve the message ID after sending by sendmail (not SMTP) ?

CRAM-MD5

Is there any plan to add CRAM-MD5 support?

Add ability to send calendar events

Calendar events are typically sent by email in a three-part multipart/alternative MIME structure where the parts are text/html, text/plain and text/calendar. Because PHPMailer doesn't support arbitrary MIME structures, only a selection of presets, it's not possible to use it to construct a message like this, and some recent changes make it difficult to manipulate the MIME structure to accommodate it.
There is some example code for sending such messages here, but it would be nice to roll this into PHPMailer.

Syntax error

In line 271 in phpmailer.inc.php file there is line:
$header[] = sprintf("Content-Transfer-Encoding: %s\n", $this->$Encoding);

$ sine before Encoding ($Encoding) causes error.

Integrate html2text

The MsgHTML function contains a 1-line html to text conversion that's over-simple and probably represents an XSS security hole. There are numerous options for better conversions such as html2text or by using an external converter (I like elinks as it can preserve table layouts in plain text). First step should be to break out a conversion function so that it's simple to add/override other converters later.

Strange characters in HTML mails on iOS

This isnt a real issue rather a question.

I'm using phpMailer in a WordPress plugin and send HTML mails. This works very well. But unfortunataly some users have these strange characters on german Umlauts and the   for instance.

This normally happens when using a different charset rather than UTF-8 but this is not the case. I don't allow users to change that and as long they don't change the code (what they don't do) there are no hooks or filters to change it too.

The strangest thing is when they send me the exact same message to me and I have no problems on my iPhone

Has anyone experienced similar? I hardly get this support request but every time I have to say that I don't know an answer.

Sign() method places headers wrong

Hi,

Im using the Sign() method to sign my emails with a certificte. Unfortunatly the headers generated by this method are not places under the existing headers, resulting in an email containing these headers in Outlook.
The message is readable in GMail, but if you click 'view original' you can see the headers being wrongly places.

Example:

MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boundary="----A15A468A5619A1EEEBA97BAD3B034332"

This is an S/MIME signed message

------A15A468A5619A1EEEBA97BAD3B034332
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="iso-8859-1"

This shows up in the Outlook email

From property doesn't work

Hi,

I have a problem with the "From" property in PHPMailer.
I'm using GMail (as SMTP and sender) and when I receive a mail sent by PHPMailer, it has the good "FromName" property but not the "From" one (it shows the SMTP address instead).

That's my code :

// SMTP Settings
$phpmailer->From = $settings['from_email'];
$phpmailer->FromName = $settings['from_name'];

Thanks !

Missing translations

There are quite a few missing translations. Can anyone help complete them?

To get a list of wha needs fixing, run test/phpmailerLangTest.php with PHPUnit and it will give a list of all missing (and stray extra) translations.

PHP errors in test_script/index.php

Three minor code errors in /test_script/index.php:

  1. Line 190 ... "Assigning the return value of new by reference is deprecated"
    Fix by changing $h2t =& new html2text($body); to $h2t = new html2text($body);

  2. Line 213 ... "Undefined variable: errorMsg"
    Fix by changing if ( count($errorMsg) > 0 ) { to if ( isset($errorMsg) && count($errorMsg) > 0 ) {

  3. Not sure how/where to fix, but the inline image is received as a broken image in gmail (after clicking "Display images below").

Fix issues from SourceForge

An umbrella ticket to remind us to fix the remaining bugs logged on SourceForge. Tickets marked as 'accepted' have been confirmed to still exist in the current version. Those marked 'open' have not been confirmed.

SMTP authentication issue.

Ok, this is the first bug that I ever report on github, so if don´t follow the proper formatting please tell me. By implementing the SMTP example I got the error "could not connect to SMTP host", The fix was to comment out $mail->IsSMTP();. Is this a bug or is it just bad implementation on my part?

It seems like more people have had similar issues since I found the quick fix on http://stackoverflow.com/questions/1233291/problem-with-smtp-authentication-in-php-using-phpmailer-with-pear-mail-works.

Improve qmail support

Some parts of PHPMailer do not play nice with qmail, particularly its implementation of sendmail (in qmail-inject) as it's incompatible with some of the command line switches used by PHPMailer.
I've already implemented some of it in this branch, upgrading qmail to a whole new Mailer type rather than treating it as a flavour of sendmail. It should be working, but it needs testing in a qmail environment before merging into trunk.

Message was not sent.Mailer error: You must provide at least one recipient email address.

Hi,

I've been using phpMailer for sometime and its been great.

I have just moved over to a new web hosting company and now it will not work. Even the most basic example.

I have PHP 5.3.3 running on the server
its a Linux server

the error back from php mailer is,
Message was not sent.Mailer error: You must provide at least one recipient email address.

I know its a valid email address.

The error message in the web hosting log is this,

[Wed Jan 23 18:47:49 2013] [warn] [client 82.68.41.46] mod_fcgid: stderr: PHP Warning: preg_match() [function.preg-match]: Compilation failed: reference to non-existent subpattern at offset 10 in /var/www/vhosts/vision-link.co.uk/site1/VL_Mail/class.phpmailer.php on line 667

any ideas? I'm a bit stuck really..

many thanks,
Patrick

ValidateAddress returns false on valid address

I've tried a basic email like [email protected] and the function returns false. Here is a better one:

function ValidateAddress($email){

    $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
    $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
    $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
        '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
    $quoted_pair = '\\x5c[\\x00-\\x7f]';
    $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
    $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
    $domain_ref = $atom;
    $sub_domain = "($domain_ref|$domain_literal)";
    $word = "($atom|$quoted_string)";
    $domain = "$sub_domain(\\x2e$sub_domain)*";
    $local_part = "$word(\\x2e$word)*";
    $addr_spec = "$local_part\\x40$domain";

    return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}

Return path lacks <>

Flagged by the IETF MsgLint application. The return path header is constructed by just appending the address to the header key, when it should be enclosed in <>.

Add missing release tags

Hi guys,

I noticed that a number of tags from Google Code repository are missing here (from 5.2.0 to 5.2.4), It would be nice if you could add them.

Cheers

Boundary quotes

Maybe slowpoke but happened to notice the boundaries are not enclose in quotes any more.
RFC 1521 - 7.2.1. : "This is not always necessary, but never hurts."
Content-Type: multipart/mixed;
boundary="gc0p4Jq0M:2Yt08jU534c0p"

Wrong message

1.wrong message by throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
2.At function SmtpSend($header, $body)
3.Method "$this->smtp->Mail($smtp_from)"

This function will check the connection and some error reporting.
But $this->Lang('from_failed') is just say "wrong from address".
We can be output more helpful messages.

Regards,
Yoshi Sakai

Always timeout in class.phpmailer.php on 754

When I'm using phpmailer on a Server CentOS 6.4, php 5.4.4( XAMPP ), and PCRE_VERSION 8.12 2011-01-15, I always got Fatal error: Maximum execution time of 30 seconds exceeded in /class.phpmailer.php on line 754. I find that is a method ValidateAddress(), which uses regular expression. After I commented regular expressions , the script can complete.
Besides the same script regular expression version run normally on my windows pc.

DKIM fails if you're signing mail with a certificate

Posted here some time ago: https://code.google.com/a/apache-extras.org/p/phpmailer/issues/detail?id=149 , didn't know you switched to GitHub.

Reported by [email protected], May 26, 2013
What steps will reproduce the problem?

  1. Create an e-mail (new PHPMailer)
  2. Set your DKIM variables
  3. Sign your e-mail with your certificate using Sign() Method.

What is the expected output? What do you see instead?

Expected: DKIM pass even if you're using a certificate to sign an e-mail or not.
Instead: "Result: fail (wrong body hash: expected C49jdpzgT23JFade5ud2KbKBHdQ=)" from [[email protected]] if you Sign() the mail with the certificate.

What version of the product are you using? On what operating system?

PHPMailer 5.2.6, PHP 5.3, CentOS

Please provide any additional information below.

Some code:
//DKIM STUFF
$m -> DKIM_domain = 'domain.com';
$m -> DKIM_private = './.dkim.txt';
$m -> DKIM_selector = 'domain.com';

//DIGITALY SIGN E-MAIL WITH A CERTIFICATE
$m -> Sign('./.cert.pem', './.cert.pem', "certPassword");

This is part of the code.
If I comment out the line with the Sign() method, the DKIM check passes. If I let it there, I get my e-mail digitally signed with the certificate, but DKIM fails.
#1 [email protected]

Forgot to mention that it doesn't work as it should ( = DKIM doesn't pass), even if you call the Sign() method before or after setting the DKIM variables.

my Registration log-in form that uses PHP-Mailer works for a couple of days now its not

when i turn on the debugging, i saw this lines of code... seems like something is changing my dfault PHPMailer setting to this domain server hence it will not work any more...my question is,,,where this code came from anyway? i did all my test in real time...is it possible that google or yahoo reported my ISP as a SPAMBOT? hence blocking my PHPMailer default and changing to this mail5002.site4now.net which i did not set? or my server is was hack? im using a microsoft hosting servers so can anyone hack microsoft server then?

SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "220 mail5002.site4now.net " 
SMTP -> get_lines(): $data is "220 mail5002.site4now.net " 
SMTP -> FROM SERVER:220 mail5002.site4now.net 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250-mail5002.site4now.net Hello [10.10.28.130] " 
SMTP -> get_lines(): $data is "250-mail5002.site4now.net Hello [10.10.28.130] " 
SMTP -> get_lines(): $data was "250-mail5002.site4now.net Hello [10.10.28.130] " 
SMTP -> get_lines(): $str is "250-SIZE 31457280 " 
SMTP -> get_lines(): $data is "250-mail5002.site4now.net Hello [10.10.28.130] 250-SIZE 31457280 " 
SMTP -> get_lines(): $data was "250-mail5002.site4now.net Hello [10.10.28.130] 250-SIZE 31457280 " 
SMTP -> get_lines(): $str is "250-AUTH LOGIN CRAM-MD5 " 
SMTP -> get_lines(): $data is "250-mail5002.site4now.net Hello [10.10.28.130] 250-SIZE 31457280 250-AUTH LOGIN CRAM-MD5 " 
SMTP -> get_lines(): $data was "250-mail5002.site4now.net Hello [10.10.28.130] 250-SIZE 31457280 250-AUTH LOGIN CRAM-MD5 " 
SMTP -> get_lines(): $str is "250 OK " 
SMTP -> get_lines(): $data is "250-mail5002.site4now.net Hello [10.10.28.130] 250-SIZE 31457280 250-AUTH LOGIN CRAM-MD5 250 OK " 
SMTP -> FROM SERVER: 250-mail5002.site4now.net Hello [10.10.28.130] 250-SIZE 31457280 250-AUTH LOGIN CRAM-MD5 250 OK 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 " 
SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6 " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 " 
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "235 Authentication successful " 
SMTP -> get_lines(): $data is "235 Authentication successful " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250 OK Sender ok " 
SMTP -> get_lines(): $data is "250 OK Sender ok " 
SMTP -> FROM SERVER:250 OK Sender ok 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "550 No such user here " 
SMTP -> get_lines(): $data is "550 No such user here " 
SMTP -> FROM SERVER:550 No such user here 
SMTP -> ERROR: RCPT not accepted from server: 550 No such user here 
SMTP Error: The following recipients failed: [email protected]

IsSMTP deprecated

Hello,
I just saw the "IsSmtp" was obsolete.
By What should replace it ?
The examples you provide always use.
thank you

Make MsgHTML normalize line breaks by default

I see a lot of messages sent by PHPMailer that clearly have had their bodies supplied with UNIX LF line breaks, and when they get q-p encoded, look very ugly and almost unreadable as all the line breaks turn into =0A and the text ends up as a solid block, thus defeating much of the point of q-p encoding. Worse than that, I also see quite a lot of bodies supplied with mixed line break formats (e.g. where a CRLF template has LF content injected into it) that make even more of a mess.
Normalizing line breaks to CRLF in HTML and plain-text bodies would result in much better looking and more readable emails, as well as saving 1 char for every line break.
If this is done in MsgHTML, which is very much a convenience function that does lots of things for you already, it would still allow setting of non-normalized message bodies by setting Body and AltBody directly.
Just wondering if anyone had any comment on this before I implement it.

Same filename causes wrong image embedding

If you embed images and use two files with the same name (but different path) phpMailer always strips out one of them

The fix is simple:

on line 2422 change
$cid = 'cid:' . md5($filename);
to
$cid = 'cid:' . md5($url);

this will generate a md5 from the whole file path instead just the filename

Header lines can be too long

The EncodeHeader function has two problems:

  1. If a header needs Q or B encoding, it also gets folding applied, but if a line has no characters that need encoding, but is still too long, it will not get folded.
  2. When a header does get folded, it only takes into account the length of the value, not the key, and the combination of the two can make the line too long.

This makes me think that the folding is applied at the wrong point. Header values should be encoded and returned, and folded later after combining with their keys. That said, I don't know if Q and B encoded headers really need their prefixes applied on every line, which is what they are doing at present.

Update: Q and B encodings do need their prefixes repeating on each line because an RFC 2047 'encoded-word' may not contain white space, and thus cannot be folded.

Packagist package uses private clone URL

The package on packagist.org uses Synchro's private clone URL, and as such composer fails with an SSH authentication error.

Please update the package to use the public clone URL.

Error message: Class phpmailer does not exist

Hello,

I install the bundle in laravel 3.2:

php artisan bundle:install phpmailer
Fetching [phpmailer]...done! Bundle installed.

But apears error mesagem:

Class phpmailer does not exist
Location:
/home/helder/php/zeladoria/laravel/ioc.php on line 155

Where am i mistaking ?

Helder

Getting Error

Hi people, anybody knows why i get this error, "Mailer Error: Could not execute: /var/qmail/bin/sendmail" or "Could not instantiate mail function." in every example i try to test.

I'm using WAMP for this.

Please add support for 'format=flowed' plain text messages to prevent "From-munging"

Firstly, thank you to all those who have contributed to PHPMailer and have made it the leading mail helper for PHP.

As per RFC 3676, could you please add 'format=flowed' mime type parameter to message bodies of content-type 'text/plain' and update the text accordingly or add a way of adding this parameter.

The main problem is that many mail systems "From-munge" in-transit messages by replacing all body text lines beginning with 'From ' with '>From '. Please see RFC 3676 section 4.4 for details. I believe this is to do with quoting of text when replying or forwarding messages. Because of this, if you write a plain text message that includes a line such as 'From mum with love', you'll find it has been prefixed with '>'.

Most modern mail clients including Thunderbird Mail, set the Content-Type of the plain text section to "text/plain; charset=ISO-8859-1; format=flowed" (or UTF-8 for charset) and use 'Space-Stuffing' on user inputted text to prevent lines from being munged (they prefix lines beginning with 'From ' or '>' or a space with ' '. There are also rules for how lines are soft wrapped that could be used in conjunction with the WordWrap option.

As a test, you can write an email in Thunderbird Mail to yourself that contains a line such as 'From blah' and view the message source on the sent or received message and you will see that the the 'From blah' line has been prefixed with a space and they always set the content type of plain text sections to include "format=flowed".

Here is RFC 3676 section 4.4 about Space-Stuffing:

4.4. Space-Stuffing

In order to allow for unquoted lines which start with ">", and to
protect against systems which "From-munge" in-transit messages
(modifying any line which starts with "From " to ">From "),
Format=Flowed provides for space-stuffing.

Space-stuffing adds a single space to the start of any line which
needs protection when the message is generated. On reception, if the
first character of a line is a space, it is logically deleted. This
occurs after the test for a quoted line (which logically counts and
deletes any quote marks), and before the test for a flowed line.

On generation, any unquoted lines which start with ">", and any lines
which start with a space or "From " MUST be space-stuffed. Other
lines MAY be space-stuffed as desired.

(Note that space-stuffing is conceptually similar to dot-stuffing as
specified in [SMTP].)

To implement this, GetBoundary() would need to check for content type of 'plain/text' and append "format=flowed" to the "Content-Type: " string, and the plain body text would need to be updated using a simple regex to at least prefix 'From ' and lines beginning with a space. Lines beginning with '>' should indicate quoted reply/forwarded text but users can prefix these lines with a space themselves if need be if they do not want mail clients to automatically convert these to nicely formatted block quotes.

Currently we are telling our developers and design teams to ensure mail messages do not include lines starting with 'From ' such as 'From Account:' to avoid this minor but annoying mail artifact that mail clients hide from users for a reason.

I'm not sure if 'format=flowed' would be useful for other content-types like 'text/html' too, as lines starting with 'From ' are munged in HTML body content as well. Thunderbird Mail does NOT add "format=flowed" to HTML body text but that is because the HTML content is nicely indented.

Many thanks,
Brendan

Possible bug within MsgHTML for embedding images

I believe there's a bug in PHPMailer for embedding images. The issue - as far as I can tell - is that that cid: use with AddEmbeddedImage is incorrect.

Around line 2491, this line exists:
$cid = 'cid:'. md5($url).'@phpmailer.0'; //RFC2392 S 2

This creates a string with the prefix of cid: at the front, which is later passed to AddEmbeddedImage and this appears to be the issue, as the cid: prefix should not be passed as part of the CID. Instead of embedding the image, it comes through as a standard attachment.

Here's how I fixed it. I removed the cid: prefix from here:
$cid = md5($url).'@phpmailer.0'; //RFC2392 S 2

And added it back in the preg_replace on line 2496 here:
$message = preg_replace("/".$images[1][$i]."=["']".preg_quote($url, '/')."["']/Ui", $images[1][$i]."="cid:".$cid.""", $message);

Test it out, make sure I'm making sense. Thanks!

PHPMailer::setFrom $auto should be FALSE by default

Hi,

I suggest changing the default value of the $auto argument in PHPMailer::setFrom to 0. Currently every call to ::setFrom also sets the Reply-To header, which is not expected. Especially for old code ported to the new PHPMailer source.

Adding From as Reply-To also serves no purpose, if no other Reply-To is set. Currently the actions of ::setFrom depends on the invocation order in PHPMailer (other behaviour, if Reply-To is already set), which is a violation of the orthogonality criteria for API developers.

Compilation failed: reference to non-existent subpattern at offset

When sending an email with valid email address I get warning:

PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Compilation failed: reference to non-existent subpattern at offset 10 in /var/www/acteo/guia/lib/class.phpmailer.php on line 738

And then error:

Mailer Error: You must provide at least one recipient email address.

Searching I've seen this is a known issue but I didn't find any solution, so I open an issue.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.