zendframework / zend-mail Goto Github PK
View Code? Open in Web Editor NEWMail component from Zend Framework
License: BSD 3-Clause "New" or "Revised" License
Mail component from Zend Framework
License: BSD 3-Clause "New" or "Revised" License
Would be nice to have an "easy" way of accessing the human-text-body part like it was possible with ZF1's Zend_Mail
(using getBodyText()
, getBodyHtml()
).
With current implementation of Zend\Mail\Message
, theses human bodies are anonymous parts of the body (a Zend\Mime\Message
). Once added there is no easy way of fetching the HTML body for instance.
When building an e-mail it can be useful to alter the already-set body.
My workaround is to loop on each Zend\Mime\Part
and find the one(s) having "text/html" type (or "text/plain" when looking for plain text body).
Summary
On Windows with PHP 7, when sending an mail message with the Sendmail transport, the subject header is duplicated.
Steps to reproduce
To reproduce the bug the sample from here can be used:
http://framework.zend.com/manual/current/en/modules/zend.mail.introduction.html
The resulting mail headers look something like this:
Subject: Test Subject
Date: Wed, 29 Jul 2015 17:33:17 +0000
From: =?UTF-8?Q?test?= [email protected]
To: [email protected]
Subject: Test Subject
Cause
In the Sendmail transport all headers (including the Subject) and the subject itself are passed to the php mail function:
$result = mail($to, $subject, $message, $headers);
The mail function then appends to the $subject to the $headers. I do not think the php mail function should handle this case because it doesn't know what subject the caller intended to use. However I believe php mail should at least issue a warning (TBD: file enhancement at https://bugs.php.net/).
Solution
Pass the headers without the Subject header to the php mail function. This is already done if the os is not Windows in the prepareHeaders. I think it should be done for Windows as well.
I use zend-mail to send an register mail through SMTP with TLS and plain auth.
Here is the used code:
<?php
namespace App\Mail\Service;
use Zend\Mail\Transport\Smtp;
use Zend\Mail\Transport\SmtpOptions;
use Zend\Mail\Message;
class MailService
{
private $transport;
private $options;
public function __construct() {
$this->transport = new Smtp();
$this->options = new SmtpOptions([
'name' => 'XXXXXX',
'host' => 'XXXXXX',
'port' => 587,
'connection_class' => 'plain',
'connection_config' => [
'username' => 'XXXXXX',
'password' => 'XXXXXX',
'ssl' => 'tls'
],
]);
$this->transport->setOptions($this->options);
}
public function sendRegisterMail($email)
{
$message = new Message();
$message->addFrom('XXXXXX', 'XXXXXX');
$message->addTo($email);
$message->setEncoding("UTF-8");
$message->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=UTF-8');
$message->setSubject('Subject');
$message->setBody('This is the Message Body');
$this->transport->send($message);
}
}
?>
When I'm calling this function the above error message appears. ICONV is installed and working, even NetBeans 8.2 recognizes the function in autocomplete. So I have no idea why this error occurs.
Regards,
Unreality
Zend\Mime\Decode::splitMessage() uses strtok() to search for \n in the message part. As of PHP 4.1.0, strtok() won't return an empty string if the $str starts with the $token, so if there are no headers and no whitespace (explicitly allowed via RFC 1341) and only 1 carriage return at the start of the part, the first line of the part is checked for a header format. If that line contains a colon, the code thinks it's a header and fails to parse it.
Here's code that demonstrates the issue:
<?php
require_once __DIR__.'/vendor/autoload.php';
$msg = <<<EOD
X-Original-To: [email protected]
From: Nathaniel Borenstein <[email protected]>
To: Ned Freed <[email protected]>
Subject: Sample message
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="simple boundary"
This is the preamble. It is to be ignored, though it
is a handy place for mail composers to include an
explanatory note to non-MIME compliant readers.
--simple boundary
This is implicitly typed plain ASCII text. 10:00:00 PM
It does NOT end with a linebreak.
--simple boundary--
This is the epilogue. It is also to be ignored.
EOD;
$obj = new Zend\Mail\Storage\Message(array('raw' => $msg));
$obj->countParts();
TLDR; All tables should be in the format of GHFM using
|
and-
as horizontal and vertical separators respectively
Check all tables are in the correct format. Please don't use leading and trailing |
- more information on github flavoured markdown tables can be found here.
please, close
Cloned this from zf2 issue repository for correct assignment to zend-mail:
Hi,
since ZF v2.4.x, I cannot send any mails to recepients containing German umlauts in their mail address.
For exmaple: testäöü@gmail.com
Encoding is set to UTF-8 on Zend\Mail\Message object.
The following expection is thrown:
Invalid header value detected #0 foobar\vendor\zendframework\zend-mail\src\Header\AbstractAddressList.php(114): Zend\Mail\Header\HeaderValue::assertValid('test\xC3\xA4\xC3\xB6\xC3\xBC@gmai...') #1 foobar\vendor\zendframework\zend-mail\src\Header\AbstractAddressList.php(158): Zend\Mail\Header\AbstractAddressList->getFieldValue(true) #2 foobar\vendor\zendframework\zend-mail\src\Headers.php(422): Zend\Mail\Header\AbstractAddressList->toString() #3 foobar\vendor\zendframework\zend-mail\src\Transport\Smtp.php(332): Zend\Mail\Headers->toString() #4 foobar\vendor\zendframework\zend-mail\src\Transport\Smtp.php(238): Zend\Mail\Transport\Smtp->prepareHeaders(Object(Zend\Mail\Message)) #5 foobar\vendor\Solar\library\Solar\Mail\Mail.php(144): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message)) #6 foobar\vendor\Solar\library\Solar\Client\AbstractClient.php(249): Solar\Mail\Mail->sendSmtp('processrevenuec...', Array, true, '') #7 foobar\modules\eonde\Processrevenuecheck.php(73): Solar\Client\AbstractClient->sendMail('test\xC3\xA4\xC3\xB6\xC3\xBC@gmai...', '', Array) #8 foobar\vendor\Solar\library\Solar\Bootstrap\Bootstrap.php(248): modules\eonde\Processrevenuecheck->run() #9 foobar\index.php(80): Solar\Bootstrap\Bootstrap->getResponse() #10 {main}
Umlauts work fine with the subject and body.
Also, the value passes the \Zend\Validate\EmailAddress validator.
It might be related to this issue although I cannot gain any workaround from it:
zendframework/zendframework#7501
Update:
Seems like RFC6531 was implemented in zend-validate but not yet zend-mail.
Hello.
There is a function setHeaderEncoding mentioned here http://framework.zend.com/manual/current/en/modules/zend.mail.encoding.html, but could not find in the current code.
Message headers are always encoded to QuotedPrintable, could not find any way to encode to base64 https://github.com/zendframework/zend-mime/blob/master/src/Mime.php#L244
May be I am wrong, but imho there is some kind of misunderstanding in setting headers' charset encoding and mime encoding. May be some function naming refactorings are required. setCharsetEncoding and setMimeEncoding functions may be suitable ones.
TLDR; Check blockquotes are formatted correctly using
>
and check headings in blockquotes are using###
Blockquotes are donated by a single greater than character and then a space. Make sure all the blockquotes in every doc file are correctly formatted. Headings in blockquotes should use ###
and not bold.
Any paragraph spacing in blockquotes should be marked using a single greater than, then a space.
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7655
User: @stmaxvl
Created On: 2015-12-28T12:01:52Z
Updated At: 2016-02-13T15:34:07Z
Body
I use Zend\Mail\Storage\Pop3 to get message.
ZF Version 2.5.1
Code:
$mail = new \Zend\Mail\Storage\Pop3(
array(
'host' => '...',
'user' => '...',
'password' => '...',
'ssl' => 'SSL'
));
$count = $mail->countMessages();
for($messageNum=1; $messageNum<=$count; $messageNum++){
$message = $mail->getMessage($messageNum);
}
Trace error:
Invalid header value detected#0 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Header\GenericHeader.php(35): Zend\Mail\Header\GenericHeader::splitHeaderLine('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#1 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Headers.php(231): Zend\Mail\Header\GenericHeader::fromString('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#2 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Headers.php(95): Zend\Mail\Headers->addHeaderLine('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#3 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Part.php(108): Zend\Mail\Headers::fromString('X-Yandex-Folder...')
#4 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Message.php(54): Zend\Mail\Storage\Part->__construct(Array)
#5 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Pop3.php(65): Zend\Mail\Storage\Message->__construct(Array)
#6 C:\xampp\htdocs\master4u\module\PpModuleMailer\src\PpModuleMailer\Controller\ConsoleController.php(82): Zend\Mail\Storage\Pop3->getMessage(1)
The fix provided in PR #12 strips comments from within quoted strings. As per RFC5322#3.2.2 this should not happen:
Strings of characters enclosed in parentheses are considered comments
so long as they do not appear within a "quoted-string", as defined in
section 3.2.4. Comments may nest.
Add ability to specify whether EmailAddressValidator used by AddressList should validate the email with the strict
flag set or not.
I use Zend in ESPOCRM but i have been having issues with receiving attachments from some users the attachments still remain on the email server but they do not make it in the import any help would be great
this is the error it kicks out in the raw email
Line "-0700 (PDT)"does not match header format!
ESPOcrm 4.2.5
Ubuntu 14.04 LTS
Apache/2.4.7 (Ubuntu)
Zend 2.5.2 - 2015-09-10
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/6824
User: @wizzvet-cborsenberger
Created On: 2014-10-31T16:34:01Z
Updated At: 2015-03-02T13:25:14Z
Body
User: @Martin-P
Created On: 2014-11-05T08:29:17Z
Updated At: 2014-11-05T08:29:17Z
Body
Please check Travis errors. There is a test failing.
User: @weierophinney
Created On: 2015-02-19T20:07:26Z
Updated At: 2015-02-19T20:07:26Z
Body
@wizzvet-cborsenberger Your change introduces a test failure in ZendTest\Mail\MessageTest::testRestoreFromSerializedString
. Can you review, please?
I see error when mail have format with UTF8 Võ Ngọc, Minh
Exception: exception 'Zend\Mail\Exception\InvalidArgumentException' with message 'The input is not a valid email address. Use the basic format local-part@hostname' in /mdata/libraries/ZendFramework2/library/Zend/Mail/Address.php:41 Stack trace: #0 /mdata/libraries/ZendFramework2/library/Zend/Mail/AddressList.php(249): Zend\Mail\Address->__construct('Nguy\xC3\xAA\xCC\x83n L\xC6\xB0u ...', NULL) #1 /mdata/libraries/ZendFramework2/library/Zend/Mail/AddressList.php(35): Zend\Mail\AddressList->createAddress('Nguy\xC3\xAA\xCC\x83n L\xC6\xB0u ...', NULL) #2 /mdata/libraries/ZendFramework2/library/Zend/Mail/AddressList.php(113): Zend\Mail\AddressList->add('Nguy\xC3\xAA\xCC\x83n L\xC6\xB0u ...', NULL) #3 /mdata/libraries/ZendFramework2/library/Zend/Mail/Header/AbstractAddressList.php(74): Zend\Mail\AddressList->addFromString('Nguy\xC3\xAA\xCC\x83n L\xC6\xB0u ...') #4 /mdata/libraries/ZendFramework2/library/Zend/Mail/Headers.php(479): Zend\Mail\Header\AbstractAddressList::fromString('From: =?UTF-8?Q...') #5 /mdata/libraries/ZendFramework2/library/Zend/Mail/Headers.php(314): Zend\Mail\Headers->lazyLoadHeader(14) #6 /mdata/libraries/ZendFramework2/library/Zend/Mail/Storage/Part.php(291): Zend\Mail\Headers->get('from') #7 /mdata/libraries/ZendFramework2/library/Zend/Mail/Storage/Part.php(365): Zend\Mail\Storage\Part->getHeader('from', 'string') #8
Thank you very much.
Hi all,
i have a directory with a huge amount of Mails, so i decided to use the Zend\Mail\Storage\Maildir Class for getting all Mails within this directory. See my code:
<?php
use Zend\Mail\Storage\Maildir;
require __DIR__ . '/vendor/autoload.php';
$mails = new MailDir(
array(
'dirname' => __DIR__ . '/maildir/',
)
);
$count = $mails->countMessages();
$emails = array();
$message = $mails->getMessage(1);
var_dump($message->getHeaders()->get('To')->getFieldValue());
I guess there is an bug and an unhandled feature.
Bug: With the code above i got an exception
Fatal error: Uncaught exception 'Zend\Mail\Storage\Part\Exception\InvalidArgumentException' with message 'no file given in params' in /Users/nico/Workspaces/MailTest/vendor/zendframework/zend-mail/src/Storage/Part/File.php on line 37
The problem is that in Maildir.php::getMessage($id)
public function getMessage($id)
{
// TODO that's ugly, would be better to let the message class decide
if ($this->messageClass === Message\File::class
|| is_subclass_of($this->messageClass, Message\File::class)
) {
return new $this->messageClass([
'file' => $this->getFileData($id, 'filename'),
'flags' => $this->getFileData($id, 'flags'),
]);
}
return new $this->messageClass([
'handler' => $this,
'id' => $id,
'headers' => $this->getRawHeader($id),
'flags' => $this->getFileData($id, 'flags'),
]);
}
At least in PHP 5.5.30, other i couldn't test at the moment, the if isn't true, and so the Message/File class is called with wrong parameters.
is_subclass_of($this->messageClass, Message\File::class) // = false
$this->messageClass // = \Zend\Mail\Storage\Message\File
Message\File::class // = Message\File
So i used my own Maildir class as a child class:
class MyMailDir extends \Zend\Mail\Storage\Maildir
{
public function __construct($params)
{
parent::__construct($params);
}
public function getMessage($id)
{
// TODO that's ugly, would be better to let the message class decide
if (strtolower($this->messageClass) == '\zend\mail\storage\message\file'
|| is_subclass_of($this->messageClass, '\Zend\Mail\Storage\Message\File')) {
return new $this->messageClass(
[
'file' => $this->getFileData($id, 'filename'),
'flags' => $this->getFileData($id, 'flags'),
'EOL' => "\n",
]
);
}
return new $this->messageClass(['handler' => $this, 'id' => $id, 'headers' => $this->getRawHeader($id),
'flags' => $this->getFileData($id, 'flags')]);
}
}
For now i could instance and run getMessage correctly.
Unhandled Feature: Furthermore in Part\File.php there is a possibility to call Headers::from String with EOL Parameter. To use this feature also with Maildir class it should be possible to hand over the parameter from params. Example above in MyMailDir::getMessage($id). Okay it should come from initial parameters for example:
$mails = new MailDir(
array(
'dirname' => __DIR__ . '/maildir/',
'EOL' => "\n",
)
);
TLDR; Headers should use the
#
,##
etc to format different levels of headers, and not be underlines using=====
or ``-----`, or be psuedo header using bold
Check all headers on the documentation - headers should use the hash style of declaration rather then be underlined with equals or dashes. The more hashes, the more of a subheading. Eg:
#
is equal to <h1>
##
is equal to <h2>
###
is equal to <h3>
####
is equal to <h4>
#####
is equal to <h5>
Headings should be appropriate for their level in the documentation.
Psuedo headers using bold tags **
should be replaced with appropriate level of heading tag.
Per RFC 7103 section 7.3, having whitespace on an otherwise empty line is deprecated but still valid. I'm running into this with emails generated by some Microsoft product.
Code to reproduce the error:
require __DIR__.'/vendor/autoload.php';
$src = "From: [email protected]
To: [email protected]
Subject: This is your reminder
about the football game tonight
Date: Wed, 20 Oct 2010 20:53:35 -0400
Don't forget to meet us for the tailgate party!
";
new Zend\Mail\Storage\Message(array('raw' => $src));
This results in:
PHP Fatal error: Uncaught exception 'Zend\Mail\Exception\RuntimeException' with message 'Malformed header detected' in vendor/zendframework/zend-mail/src/Headers.php:88
vendor/zendframework/zend-mail/src/Headers.php:88
vendor/zendframework/zend-mime/src/Decode.php:142
vendor/zendframework/zend-mail/src/Storage/Part.php:105
vendor/zendframework/zend-mail/src/Storage/Message.php:54
One workaround is to use pipe the message source through formail first and tell it to merge header lines:
formail -c -f
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7654
User: @renecatharsis
Created On: 2015-12-21T12:08:38Z
Updated At: 2016-02-13T15:34:02Z
Body
Hi,
since ZF v2.4.x, I cannot send any mails to recepients containing German umlauts in their mail address.
For exmaple: testäöü@gmail.com
Encoding is set to UTF-8 on Zend\Mail\Message object.
The following expection is thrown:
#0 foobar\vendor\zendframework\zend-mail\src\Header\AbstractAddressList.php(114): Zend\Mail\Header\HeaderValue::assertValid('test\xC3\xA4\xC3\xB6\xC3\xBC@gmai...')
#1 foobar\vendor\zendframework\zend-mail\src\Header\AbstractAddressList.php(158): Zend\Mail\Header\AbstractAddressList->getFieldValue(true)
#2 foobar\vendor\zendframework\zend-mail\src\Headers.php(422): Zend\Mail\Header\AbstractAddressList->toString()
#3 foobar\vendor\zendframework\zend-mail\src\Transport\Smtp.php(332): Zend\Mail\Headers->toString()
#4 foobar\vendor\zendframework\zend-mail\src\Transport\Smtp.php(238): Zend\Mail\Transport\Smtp->prepareHeaders(Object(Zend\Mail\Message))
#5 foobar\vendor\Solar\library\Solar\Mail\Mail.php(144): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message))
#6 foobar\vendor\Solar\library\Solar\Client\AbstractClient.php(249): Solar\Mail\Mail->sendSmtp('processrevenuec...', Array, true, '')
#7 foobar\modules\eonde\Processrevenuecheck.php(73): Solar\Client\AbstractClient->sendMail('test\xC3\xA4\xC3\xB6\xC3\xBC@gmai...', '', Array)
#8 foobar\vendor\Solar\library\Solar\Bootstrap\Bootstrap.php(248): modules\eonde\Processrevenuecheck->run()
#9 foobar\index.php(80): Solar\Bootstrap\Bootstrap->getResponse()
#10 {main}```
Umlauts work fine with the subject and body.
Also, the value passes the \Zend\Validate\EmailAddress validator.
It might be related to this issue although I cannot gain any workaround from it:
https://github.com/zendframework/zf2/issues/7501
Update:
Seems like RFC6531 was implemented in zend-validate but not yet zend-mail.
---
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7593
User: @dendemann
Created On: 2015-06-23T10:52:42Z
Updated At: 2015-10-25T07:17:23Z
Body
If a mime encoded "from" header value contains quotes, they are thrown away. Its because AbstractAddressList::fromString uses str_getcsv function to split multiple fields. str_getcsv also removes the quotes.
Can be reproduced using:
$message =
iconv_mime_encode('From', '"Quoted" <[email protected]>', ['scheme' => 'Q']) . "\r\n"
."To: [email protected]\r\n"
."Subject: plain text email example\r\n"
. "Mime-Version: 1.0\r\n"
. "Content-Type: text/plain\r\n"
."\r\n"
."I am a test message\r\n";
$msg = Zend\Mail\Message::fromString($message);
echo $msg->toString();
Result:
From: Quoted <[email protected]>
To: [email protected]
Subject: plain text email example
MIME-Version: 1.0
Content-Type: text/plain
I am a test message
The quotes around the word Quoted are gone. Would a simple explode be sufficient here instead of str_getcsv?
It's a good idea to add some recipients to an email, but these don't have to be in the To: header. Instead they could be in the "Cc:" or "Bcc:" header lines.
Because of this I think that these checks in Transport/Sendmail.php are not correct:
if (!$headers->has('to')) {
throw new Exception\RuntimeException('Invalid email; contains no "To" header');
}
$to = $headers->get('to');
$list = $to->getAddressList();
if (0 == count($list)) {
throw new Exception\RuntimeException('Invalid "To" header; contains no addresses');
}
According to RFC 5322 (http://tools.ietf.org/html/rfc5322) the only absolute necessary (as in MUST) headers are From: and Date:
The only required header fields are the origination date field and the originator address field(s). All other header fields are syntactically optional.
Of course there's usually no email that does not have a recipient, but the check should look for them in To:, Cc: and Bcc:.
I am using a Zend Mail component using Transport/Factory and SMTP configuration. I am constantly getting this error despite using proper guidelines in the Zend documentation .
Zend\Mail\Transport\Exception\InvalidArgumentException
File:
C:\xampp\htdocs\website\vendor\zendframework\zend-mail\src\Transport\Factory.php:42
Message:
Zend\Mail\Transport\Factory::create expects an array or Traversable argument; received "NULL"
Please remove the abstract
keyword from the Factory, so the class can be reused, not only inherited.
We want composition over inheritance, don't we?
The recipient listed in addCc() doesn't get the email, although the person who is in addTo() can get the email and can even see the addCc recipient's name is listed in Cc field.
We are using SMTP on IBM Domino mail server.
Tested "Cc" using pure php mail() function, it worked.
This is most liked caused by the "\r\n" in the header.
When email being parsed it retrieves message id header value
<<message-id>>
instead of
<message-id>
https://github.com/zendframework/zend-mail/blob/master/src/Header/MessageId.php#L79
Hello,
I have an E-Mail with the following "From"-Header:
From: =?UTF-8?Q?Lastname,=20Prename=20(Company=20GmbH)=20<[email protected]>?=
After decoding in Zend\Mail\AddressList\AbstractAddressList (HeaderWrap::mimeDecodeValue($fieldValue);
) it looks like this:
Lastname, Prename (Company GmbH) <[email protected]>
After $values = str_getcsv($fieldValue, ',');
$values is:
array(1) {
[0]=>
array(2) {
[0]=>
string(6) "Lastname"
[1]=>
string(24) "Prename <[email protected]>"
}
}
This leads to the following Error:
The input is not a valid email address. Use the basic format local-part@hostname
#0 /htdocs/vendor/zendframework/zend-mail/src/AddressList.php(249): Zend\Mail\Address->__construct('Lastname', NULL)
#1 /htdocs/vendor/zendframework/zend-mail/src/AddressList.php(35): Zend\Mail\AddressList->createAddress('Lastname', NULL)
#2 /htdocs/vendor/zendframework/zend-mail/src/AddressList.php(113): Zend\Mail\AddressList->add('Lastname', NULL)
#3 /htdocs/vendor/zendframework/zend-mail/src/Header/AbstractAddressList.php(75): Zend\Mail\AddressList->addFromString('Lastname')
Any Idea how to fix this?
On my windows 10/PHP 7 box I'm getting this error. This error does not effect our dev/production unix servers.
Unable to send mail: mail(): SMTP server response: 550 5.6.0 Lone CR or LF in headers (see RFC2822 section 2.2)
I don't think there is anything wrong with the code that is simply rendering a template.
$viewRenderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $viewRenderer->render($template, $data);
$html = new MimePart($content);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
$html->encoding = Mime::ENCODING_8BIT;
$body = new MimeMessage();
$body->setParts([$html]);
$message = new Message();
$message->setSubject($data['subject']);
$message->setBody($body);
$message->setTo($data['to']);
$message->setFrom($config['noreply']['email'], $config['noreply']['name']);
$message->setEncoding('UTF-8');
$transport = new Sendmail();
$transport->send($message);
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7594
User: @dendemann
Created On: 2015-06-23T18:19:29Z
Updated At: 2015-10-25T07:16:51Z
Body
A generic mail header containing the value 0 will lose that value during header parsing.
Example:
$message =
"From: [email protected]\r\n"
."To: [email protected]\r\n"
."Subject: plain text email example\r\n"
."X-Spam-Score: 0\r\n"
."X-Some-Value: 1\r\n"
."\r\n"
."I am a test message\r\n";
$msg = Zend\Mail\Message::fromString($message);
echo $msg->toString();
Result:
From: [email protected]
To: [email protected]
Subject: plain text email example
X-Spam-Score:
X-Some-Value: 1
I am a test message
I debugged my way through and found the problem within the constructor of GenericHeader:
public function __construct($fieldName = null, $fieldValue = null)
{
if ($fieldName) {
$this->setFieldName($fieldName);
}
if ($fieldValue) {
$this->setFieldValue($fieldValue);
}
}
If $fieldValue contains 0 the value won't get set. Is this wanted behavior?
User: @dendemann
Created On: 2015-06-24T08:05:48Z
Updated At: 2015-06-24T08:05:48Z
Body
I added a fix that works for me: rapidsoft-de@301d7b3
Review and comments appreciated.
User: @Martin-P
Created On: 2015-07-04T15:02:51Z
Updated At: 2015-07-04T15:02:51Z
Body
The components are split up in their own repositories. For Zend\Mail
: https://github.com/zendframework/zend-mail/issues
You can open an issue and create a pull request there (instead of a link to your fix) and it will be reviewed there.
Hi
There is a case when emails have Content-Type header, defined with keyword "ContentType", for example:
ContentType: text/html; charset="UTF-8"
In this case error appears:
Invalid header line for Content-Type string
Looking header fieldName normalization, I see that Content-Type
, Content_Type
, Content Type
, ContentType
will be normalized to contenttype
. So contenttype
will be stored in Zend\Mail\Headers::$headersKeys
and appropriate header in Zend\Mail\Headers::$headers
.
Than on header loading pluginClassLoader will load Zend\Mail\Header\ContentType
and method Zend\Mail\Header\ContentType::fromString()
is called.
But there is condition that do not accept 'contenttype` value.
It looks like inconsistent behavior. I understand that rfc2045 accepts Content-Type
keyword only, but in real cases other keywords can appear.
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/6488
User: @filipp-k
Created On: 2014-07-28T09:18:00Z
Updated At: 2016-03-10T18:05:14Z
Body
Sorry my bad English =)
After fixing #3645 bug another one rising.
Now Protocol\Smtp has this _disconnect() method:
protected function _disconnect()
{
// Make sure the session gets closed
$this->quit();
parent::_disconnect();
}
which calls in __desctuct() method of AbstractProtocol, which causes uncaught exception on exit($warningLevel) in ConsoleResponseSender:
public function __invoke(SendResponseEvent $event)
{
$response = $event->getResponse();
if (!$response instanceof Response) {
return;
}
$this->sendContent($event);
$errorLevel = (int) $response->getMetadata('errorLevel',0);
$event->stopPropagation(true);
exit($errorLevel); // GC calls __destruct(), then _disconnect(), then quit() which rises RuntimeException if server crashes
}
I have fixed this problem this way:
class Smtp extends \Zend\Mail\Protocol\Smtp
{
...
public function __destruct()
{
try {
parent::__destruct();
} catch (\Exception $e) {
// ignore
}
}
}
I don't know how correctly it is, so correct my version and I will create pull request.
User: @coolmic
Created On: 2014-11-28T12:14:39Z
Updated At: 2014-11-28T12:14:39Z
Body
Not exactly the same issue, but very likely.
I am using https://github.com/juriansluiman/SlmQueue to send email.
It open a never-ending php session. So the smtp connection is supposed to be persistent.
But sometimes, the connection is closed (by postfix maybe?).
The SmtpTransport doesn't reconnect (and there is no way to reconnect). So I tried to create another Smtp transport, on Zend\Mail\Protocol\Exception\RuntimeException.
But I get random Zend\Mail\Protocol\Exception\RuntimeException thrown because of garbage collector.
sometime when I do
$this->smtp = null;
or when gc_collect_cycles() is called from SlmQueue\Strategy\MaxMemoryStrategy .
Because the __destruct method is called, but the connection is invalid.
I fixed it the same way as @filipp-qoma .
User: @coolmic
Created On: 2016-03-10T15:32:42Z
Updated At: 2016-03-10T15:32:42Z
Body
Why close? It's still not fixed.
We should add a try catch in __destruct , or add a public method stopSession to set $this->sess = false
Should I do a pull request?
User: @Ocramius
Created On: 2016-03-10T15:36:39Z
Updated At: 2016-03-10T15:36:39Z
Body
@coolmic the proposed solution doesn't seem to be the correct one, as it fixes the symptom, not the cause...
User: @filipp-k
Created On: 2016-03-10T17:46:31Z
Updated At: 2016-03-10T17:46:31Z
Body
So propose correct one but don't close issue. Code sends BYE twice, and second time happens when connection is already closed.
User: @filipp-k
Created On: 2016-03-10T17:47:20Z
Updated At: 2016-03-10T17:47:20Z
Body
I'm so sorry about misstap...
User: @adamlundrigan
Created On: 2016-03-10T18:05:14Z
Updated At: 2016-03-10T18:05:14Z
Body
@filipp-k @coolmic it was marked "To Be Closed" has been inactive for a very long time and this repository no longer contains the code being referenced. If you wish to provide a fix for this please open a new issue and/or PR over on the Zend\Mail repository (zendframework/zend-mail) and reference this existing issue so we know this one can be closed out. Thanks!
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7324
User: @echampet
Created On: 2015-03-13T13:57:58Z
Updated At: 2015-10-25T07:09:02Z
Body
Hi,
I'm using Zend\Mail\Message::fromString()
to parse an existing mail, modify/check some stuff in the headers, and after send it via smtp.
In my headers everything is in ascii, except the subject which is utf8 (encoded in quoted printable)
parsing is fine (Mime\Decode::splitMessage
here https://github.com/zendframework/zf2/blob/67f098af070b29d5042e89e936604df3193d2212/library/Zend/Mail/Message.php#L546) and all headers in $headers have ->encoding == ascii except the subject ->encoding == utf-8
now when calling $message->setHeaders($headers);
(https://github.com/zendframework/zf2/blob/67f098af070b29d5042e89e936604df3193d2212/library/Zend/Mail/Message.php#L550), there is a call to $headers->setEncoding('ascii')
(https://github.com/zendframework/zf2/blob/67f098af070b29d5042e89e936604df3193d2212/library/Zend/Mail/Message.php#L86), but it's doing nothing except breaking encoding.
When you call setEncoding, you are only changing the 'declared' encoding, but you are not converting the data, so this can only break stuff.
For now i've just commented out //$headers->setEncoding($this->getEncoding());
(ligne 86)
I think encoding should only be stored at header (singular) level, or even better store everything in utf8, and at encoding time detect if encoding is needed (mb_detect_encoding !== 'ascii'
?)
Cullprit is 9f70feb81b5fccd7259d97971084c1d455525ae3 (December 2011)
User: @weierophinney
Created On: 2015-03-23T18:57:15Z
Updated At: 2015-03-23T18:57:15Z
Body
Could you provide a message that fails for us? We can then use that for a test case in order to correct the issue.
Thanks!
User: @echampet
Created On: 2015-03-24T08:01:24Z
Updated At: 2015-03-24T08:01:24Z
Body
hi @weierophinney
endline are CRLF
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
Subject: =?utf-8?Q?Test_for_zend_=28=C3=A9=C3=A0=C3=B9=29?=
From: [email protected]
Message-Id: <[email protected]>
Date: Tue, 24 Mar 2015 08:56:07 +0100
To: "aaa" <[email protected]>
Mime-Version: 1.0 (1.0)
Test for zend
User: @croensch
Created On: 2015-08-31T09:53:58Z
Updated At: 2015-08-31T09:53:58Z
Body
I got this one too, outlook server has attachments like:
Content-Type: application/pdf;
name="test.pdf"
That is always \r\n\t
, maybe we can add this as special case without breaking security?
When sending email using Zend SMTP transport it adds Sender header with empty value if this header was not defined:
Sender:
If you parse such an email using Zend Imap it throws an error:
Zend\Mail\Header\Exception\InvalidArgumentException: Invalid header value for Sender string
Here's the code that explain this issue:
$rawMessage = "Subject: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=\r\n"
." =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=";
$mail = \Zend\Mail\Message::fromString($rawMessage);
echo "Using Message::fromString() - ERROR (?): Subject is not mime encoded!\n";
echo $mail->toString();
unset($mail);
$mail = new \Zend\Mail\Message();
$mail->setSubject("Non “ascii” characters like accented vowels òàùèéì");
echo "Using Message::setSubject() - OK: Subject is correctly encoded!\n";
echo $mail->toString();
unset($mail);
$mail = new \Zend\Mail\Message();
$header = new \Zend\Mail\Header\GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì');
$mail->getHeaders()->addHeader($header);
echo "Using Message::getHeaders()::addHeader() - OK: Header is correctly encoded!\n";
echo $mail->toString();
unset($mail);
$mail = new \Zend\Mail\Message();
$header = new \Zend\Mail\Header\GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì');
$headers = new \Zend\Mail\Headers();
$headers->addHeader($header);
$mail->setHeaders($headers);
echo "Using Message::setHeaders(Headers \$headers) - ERROR: Throws Exception!\n";
try {
echo $mail->toString();
} catch (\Exception $e) {
echo 'EXCEPTION: ' . $e->getMessage();
echo "\n\n";
}
unset($mail);
echo "Using Header::fromString() - OK Header is correctly encoded!\n";
$mail = new \Zend\Mail\Message();
$str = "X-Test-2: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=\r\n"
." =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=";
$header = \Zend\Mail\Header\GenericHeader::fromString($str);
$mail->getHeaders()->addHeader($header);
echo $mail->toString();
unset($mail);
echo "Using Message::setHeaders(Headers \$headers) with Header::fromString()- ERROR: Throws Exception!\n";
$mail = new \Zend\Mail\Message();
$str = "X-Test-2: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=\r\n"
." =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=";
try {
$header = \Zend\Mail\Header\GenericHeader::fromString($str);
$headers = new \Zend\Mail\Headers();
$headers->addHeader($header);
$mail->setHeaders($headers);
echo $mail->toString();
} catch (\Exception $e) {
echo 'EXCEPTION: ' . $e->getMessage();
echo "\n\n";
}
unset($mail);
TLDR; Cast your eye over the documetation for any problems not covered in the other issues
Things slip through the net, so check the documentation for other problems that have been missed. Common other problems include
*
then space at the start of line)bookdown.json
file is correctly formated and has the right escapingIf you end up fixing the same problem over and over, please ping Gary Hockin - we may be able to add bespoke issue for that problem, or fix in automated capacity
There is missing service factory for mail transports like same in db and other components.
production config/autoload/local.php
return [
'mail' => [
'transport' => [
'type' => 'smtp',
'options' => [
'host' => 'smtp.example.com',
'connection_class' => 'login',
'connection_config' => [
'username' => '[email protected]',
'password' => 'xxxxxxxx',
'ssl' => 'tls'
],
],
],
],
];
testing / dev config/autoload/local.php
return [
'mail' => [
'transport' => [
'type' => 'in-memory'
],
],
];
That is may look like https://github.com/autowp/zf-components/blob/master/src/Mail/Transport/TransportServiceFactory.php
Should i just increase memory_limit to 256M (not always possible)
or do you guys are ok with loosing some raw performance?
With huge mails (50M, 660000 lines), i'm hitting memory_limit, so i've done some tests
looking at:
with php5.6/php7 (on a fedora 22, core i7, ssd)
260M/200M|0,23s/0,08s|0,29ms/0,18ms
$data = str_replace("\r", '', $data);
$data = explode("\n", $data);
foreach ($data as $line) {
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
}
200M/160M|1,5s/0,14s|1,75ms/0,22ms
foreach (preg_split('/\r?\n/', $data) as $line) {
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
}
50M/50M|0,32s/0,16s|0,86ms/0,41ms
$start = 0;
while (($stop = strpos($data, "\n", $start)) !== false) {
$len = $stop-$start;
if ($len > 0 && $data[$stop-1] === "\r") {
$len -= 1;
}
$line = substr($data, $start, $len);
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
$start = $stop + 1;
}
//last line
$line = substr($data, $start);
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
150M/100M|0,28s/0,14s|0,76ms/0,31ms
$start = 0;
$data = str_replace("\r", '', $data);
while (($stop = strpos($data, "\n", $start)) !== false) {
$line = substr($data, $start, $stop-$start);
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
$start = $stop + 1;
}
//last line
$line = substr($data, $start);
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
50M/50M|0,28s/0,18s|0,68ms/0,40ms
$fp = fopen("php://temp", "r+");
fwrite($fp, $data);
unset($data);
rewind($fp);
while (($line = stream_get_line($fp, 1000, "\n")) !== false) {
$line = rtrim($line, "\r");
if (isset($line[0]) && $line[0] === '.') {
$line = '.' . $line;
}
//send
}
All tests were run with 'php -d"memory_limit=256M" -d"opcache.enable_cli=1"'
I'm having same problem as below so I'm copying one forum post here hoping for some kind of solution.
PHP 5.6 changed the SSL certificate verification default, causing Zend_Mail SMTP to fail when the server CN doesn't exactly match the certificate CN. The solution to this is to set the verify_peer and verify_peer_name stream context options to false, but Zend_Mail provides no way to do this. The only workaround is to not use SSL in this instance, which means potentially sending userID/password in the clear.
The most flexible solution would be to have the Zend_Mail_Transport and Zend_Mail_Protocol classes accept config values to set stream context options, similar to the following:
$smtpOpts['_context_opt'] = array('ssl' => array('verify_peer' => 0, 'verify_peer_name' => 0));
Where 'ssl' is the context wrapper containing an array of context option name/value pairs.
A more limited solution would be to allow some kind of direct option that would indicate that the certificate should not be validated, and set the above context options accordingly.
Hello,
I maintain a fork that is used in a mail-related SaaS, and would like to merge those changes upstream for the community to benefit from. Would you prefer one massive PR with all of these changes, or a PR for each individual change?
You can view those changes at:
https://github.com/ameir/zf2/commits/mail-improvements
Thanks,
Ameir
When trying to load raw (QP encoded, etc) headers with:
Zend\Mail\Headers::fromString($headerString);
I came up to a problem that iconv_mime_encode can not be used reliably to validate if header can be encoded
for example (the value must be exactly like that):
$name = 'Subject';
$value = "[#77675] New Issue:xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxx, tähtaeg xx.xx, xxxx";
$header = new GenericHeader($name, $value);
the above code breaks at HeaderWrap::canBeEncoded when underlying iconv_mime_encode
attempts to wordwrap the string and fails as it needs to wrap at middle of character or something:
iconv_mime_encode(): Unknown error (7)
which results false
as return value and InvalidArgumentException later
The header will be encoded ok if the $value
is lengthened or shortened even one byte before 76th character.
I get the concept of removing the mentioned methods in ZF2 derives from the fact that a message may have several MIME parts, not only HTML and plain text. But still, most of the time nowadays we primarily compose HTML messages, secondarily with text/plain fallback. With the current concept we have to roll over and over something like this:
use Zend\Mail;
use Zend\Mime;
[...]
$body = new Mime\Message();
$bodyHtml = new Mime\Part($view->render("html-template.phtml", $viewData));
$bodyHtml->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE);
$bodyHtml->setType(\Zend\Mime\Mime::TYPE_HTML);
$bodyHtml->setCharset("UTF-8");
$bodyText = new Mime\Part($view->render("html-template.phtml", $viewData));
$bodyText->setEncoding(Mime\Mime::ENCODING_8BIT);
$bodyText->setType(\Zend\Mime\Mime::TYPE_TEXT);
$bodyText->setCharset("UTF-8");
$body->addPart($bodyText);
$body->addPart($bodyHtml);
$message = new Mail\Message();
$message->setEncoding("UTF-8");
$message->setBody($body);
$message->setFrom($senderEmail, $senderName);
$message->addTo($recipientEmail, $recipientName);
$message->setSubject($subject);
$transport = new Mail\Transport\Sendmail();
$transport->send($message);
Compared to ZF1 this is way too tedious. I am sure we could find a golden midway between keeping the current clean concept and being able to compose common messages easily.
What I am thinking of is a Zend\Mail\Message::setBodyHtml()
and Zend\Mail\Message::setBodyText()
backport as convenience methods that would add the appropriate MIME parts pushing it to the end of the parts' stack. In case the message had already have a non-multipart body, the method would make the message multipart pushing the existing body as the first part.
I am posting this to ask for opinions and your thought on this. I am doing it anyways but if the community accepts the idea I will code it in a mergeable way.
Thoughts out there?
When using smtp transport api for sending mail, 'from' header doesn't change by using
->setFrom() or ->setSender() and 'from' header always remains the same email address used for smtp user for authentication. In following example, from email address remains same as '[email protected]' instead of '[email protected]'.
Note: Sender name gets changed with 'Some Sender' (but not the email)
$transport = new SmtpTransport();
$options = new SmtpOptions();
$options->setHost('smtp.gmail.com')
->setConnectionClass('login')
->setName('smtp.gmail.com')
->setConnectionConfig(array(
'username' =>'[email protected]',
'password' => 'mypassword',
'ssl' => 'tls'
));
$transport->setOptions($options);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('[email protected]', 'Some Sender');
$mail->addTo('[email protected]', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send($transport);
From PHP 5.6, SSL/TLS client streams now enable peer verification by default.
So, error occurs when communicate with the server that is using a self-signed certificate.
See: http://php.net/manual/migration56.openssl.php
In order to avoid the above problem:
$options = [
'ssl' => [
'verify_peer_name' => false,
'verify_peer' => false,
]
];
$context = stream_context_create($options);
// ex. https://github.com/zendframework/zend-mail/blob/release-2.7.0/src/Protocol/Pop3.php#L95
// $this->socketfsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
$this->socketfsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION, $context);
In this way, there is a need to pass a stream context to the stream function.
However, the current Zend\Mail\Protocol\Pop3
and Zend\Mail\Protocol\Smtp
look like does not provide an interface to pass stream context.
Is there support for the above interface in future?
A similar way: zend-http/zend.http.client.adapters.md at release-2.5.4 · zendframework/zend-http
I use Zend\Mail\Storage\Pop3 to get message.
ZF Version 2.5.1
Code:
$mail = new \Zend\Mail\Storage\Pop3(
array(
'host' => '...',
'user' => '...',
'password' => '...',
'ssl' => 'SSL'
));
$count = $mail->countMessages();
for($messageNum=1; $messageNum<=$count; $messageNum++){
$message = $mail->getMessage($messageNum);
}
Trace error:
Invalid header value detected#0 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Header\GenericHeader.php(35): Zend\Mail\Header\GenericHeader::splitHeaderLine('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#1 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Headers.php(231): Zend\Mail\Header\GenericHeader::fromString('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#2 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Headers.php(95): Zend\Mail\Headers->addHeaderLine('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#3 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Part.php(108): Zend\Mail\Headers::fromString('X-Yandex-Folder...')
#4 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Message.php(54): Zend\Mail\Storage\Part->__construct(Array)
#5 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Pop3.php(65): Zend\Mail\Storage\Message->__construct(Array)
#6 C:\xampp\htdocs\master4u\module\PpModuleMailer\src\PpModuleMailer\Controller\ConsoleController.php(82): Zend\Mail\Storage\Pop3->getMessage(1)
I have an other issue :
$mail = new \Zend\Mail\Storage\Imap(array('host' => 'myhost',
'user' => 'mylogin',
'password' => 'mypassword'));
$mail->getMessage(194)
From debug :
( ! ) Notice: iconv_mime_encode(): Unknown error (7) in .../vendor/zendframework/zend-mail/src/Header/HeaderWrap.php on line 119
Call Stack
# Time Memory Function Location
1 0.0025 241792 {main}( ) .../index.php:0
2 0.4338 5131376 Zend\Mvc\Application->run( ) .../index.php:17
3 0.6873 5857424 Zend\EventManager\EventManager->trigger( ) .../Application.php:314
4 0.6873 5857472 Zend\EventManager\EventManager->triggerListeners( ) .../EventManager.php:205
5 0.6886 5865392 call_user_func:{/.../vendor/zendframework/zend-eventmanager/src/EventManager.php:444} ( ) .../EventManager.php:444
6 0.6886 5865888 Zend\Mvc\DispatchListener->onDispatch( ) .../EventManager.php:444
7 0.6921 5911392 Zend\Mvc\Controller\AbstractController->dispatch( ) .../DispatchListener.php:93
8 0.6922 5911856 Zend\EventManager\EventManager->trigger( ) .../AbstractController.php:118
9 0.6922 5911904 Zend\EventManager\EventManager->triggerListeners( ) .../EventManager.php:205
10 0.6939 5927832 call_user_fun:{.../vendor/zendframework/zend-eventmanager/src/EventManager.php:444} ( ) .../EventManager.php:444
11 0.6939 5927960 Zend\Mvc\Controller\AbstractActionController->onDispatch( ) .../EventManager.php:444
12 0.6940 5928152 ...\IndexController->indexAction( ) .../AbstractActionController.php:82
13 1.2227 5997920 Zend\Mail\Storage\Imap->getMessage( ) .../IndexController.php:58
14 1.2503 6042432 Zend\Mail\Storage\Message->__construct( ) .../Imap.php:118
15 1.2503 6042944 Zend\Mail\Storage\Part->__construct( ) .../Message.php:54
16 1.2512 6047184 Zend\Mime\Decode::splitMessage( ) .../Part.php:106
17 1.2542 6132128 Zend\Mail\Headers::fromString( ) .../Decode.php:141
18 1.2852 6191952 Zend\Mail\Headers->addHeaderLine( ) .../Headers.php:95
19 1.2852 6192000 Zend\Mail\Header\GenericHeader::fromString( ) .../Headers.php:231
20 1.2935 6193568 Zend\Mail\Header\GenericHeader->__construct( ) .../GenericHeader.php:37
21 1.2936 6193648 Zend\Mail\Header\GenericHeader->setFieldValue( ) .../GenericHeader.php:83
22 1.2936 6194856 Zend\Mail\Header\HeaderWrap::canBeEncoded( ) .../GenericHeader.php:129
23 1.2936 6195304 iconv_mime_encode ( ) .../HeaderWrap.php:119
From zf trace
Message:
Header value must be composed of printable US-ASCII characters and valid folding sequences.
Pile d'exécution:
#0 .../vendor/zendframework/zend-mail/src/Header/GenericHeader.php(83): Zend\Mail\Header\GenericHeader->setFieldValue('ELIE Caroline <...')
#1 .../vendor/zendframework/zend-mail/src/Header/GenericHeader.php(37): Zend\Mail\Header\GenericHeader->__construct('To', 'ELIE Caroline <...')
#2 .../vendor/zendframework/zend-mail/src/Headers.php(231): Zend\Mail\Header\GenericHeader::fromString('To: ELIE Caroli...')
#3 .../vendor/zendframework/zend-mail/src/Headers.php(95): Zend\Mail\Headers->addHeaderLine('To: ELIE Caroli...')
#4 .../vendor/zendframework/zend-mime/src/Decode.php(141): Zend\Mail\Headers::fromString('MIME-Version: 1...', '\n')
#5 .../vendor/zendframework/zend-mail/src/Storage/Part.php(106): Zend\Mime\Decode::splitMessage('MIME-Version: 1...', 'MIME-Version: 1...', '')
#6 .../vendor/zendframework/zend-mail/src/Storage/Message.php(54): Zend\Mail\Storage\Part->__construct(Array)
#7 .../vendor/zendframework/zend-mail/src/Storage/Imap.php(118): Zend\Mail\Storage\Message->__construct(Array)
#8 .../module/Ent/src/Ent/Controller/IndexController.php(58): Zend\Mail\Storage\Imap->getMessage(194)
#9 .../vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82): Ent\Controller\IndexController->indexAction()
#10 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#11 .../vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#12 .../vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 .../vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(118): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#14 .../vendor/zendframework/zend-mvc/src/DispatchListener.php(93): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#15 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#16 .../vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#17 .../vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#18 .../vendor/zendframework/zend-mvc/src/Application.php(314): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#19 .../public/index.php(17): Zend\Mvc\Application->run()
#20 {main}
I have described the problem in an article - here's is part of it exactly about the bug in the method:
After quite extensive debuging, send plenties of emails there and back I recognized the problem actually is about headers that consists local characters (for Poland examples of them might be: ź, ć, ń, ę, ą etc. - other countries might have more or less of such as well). Since messages were sent and received using different mailservers (Exchange, sendmail, Lotus) and different email clients (Outlook, Thunderbird, Windows Mail) - the headers in which these characters appeared were very different - e.g. Exchange (or Outlook - haven't checked that in 100% :) ) was adding Topic-Thread header (as far as I know for message threading) and the full topic was put in there - so this header, among others (such as Topic) also was throwing Exception once tried to be retrieved from the object.
The problem with Zend\Mail\Message::fromString() method was that it actually didn't allowed to specify encoding for the data that is retrieved from RAW message. It simply takes the data and puts into some storage inside the object - and the data itself is retrieved on a lazy-loading basis.
So once you try to retrieve the header - the getter is throwing an Exception that data is in wrong format
Here is also a code - overloaded method - that fixes that:
public static function fromString(string $rawMessage, string $encoding = 'UTF-8') {
$message = parent::fromString($rawMessage);
foreach($message->getHeaders()->toArray() as $headerName => $headerValue) {
try {
$message->getHeaders()->get($headerName);
} catch (\Zend\Mail\Header\Exception\InvalidArgumentException $e) { // catches only if Header is wrongly structured
$message->getHeaders()->removeHeader($headerName);
$header = new \Zend\Mail\Header\GenericHeader();
$header->setEncoding($encoding);
$header->setFieldName($headerName);
$header->setFieldValue($headerValue);
$message->getHeaders()->addHeader($header);
}
}
$message->getHeaders()->setEncoding($encoding); // All headers are encoded in $encoding
return $message;
}
Full information on an error including the solution itself can be found in the following article:
http://www.linkedphpers.org/2016/04/zend-framework-2-zendmailmessagefromstr.html
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7656
User: @akosphp
Created On: 2016-01-02T14:42:06Z
Updated At: 2016-02-13T15:34:17Z
Body
The isValid method doesn't support unicode characters in the header value. This is a problem for example when unicode email address is given. (eg.: üñîçøðé@example.com - which is a valid email address)
Unicode email addresses cause Zend\Mail\Header\Exception\RuntimeException in vendor\zendframework\zend-mail\src\Header\HeaderValue.php:115
Exception message: Invalid header value detected.
This issue has been moved from the zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7363
User: @echampet
Created On: 2015-03-24T15:20:50Z
Updated At: 2015-11-06T21:02:46Z
Body
Hi
#6267 isn't enough.
in https://github.com/zendframework/zf2/blob/master/library/Zend/Mail/Header/AbstractAddressList.php#L44
str_getcsv should happen before iconv_mime_decode
An exemple of "broken" header
From: =?utf-8?B?QUFBLCB0ZXN0IHdpdGggw6nDoCTDuQ==?= <[email protected]>
User: @samsonasik
Created On: 2015-03-25T02:16:43Z
Updated At: 2015-03-25T02:16:43Z
Body
PR ?
User: @echampet
Created On: 2015-03-25T13:42:01Z
Updated At: 2015-03-25T13:42:01Z
Body
@samsonasik, I'm working on many patches right now
Class 'Zend\ServiceManager\AbstractPluginManager' not found in vendor/zendframework/zend-mail/src/Protocol/SmtpPluginManager.php on line 20
PHP
$protocol->requestAndResponse('FETCH', ['3596', $protocol->escapeList(['ENVELOPE'])], false);
IMAP response
ZEND response
Notice: Uninitialized string offset: 0 in vendor/zendframework/zend-mail/src/Protocol/Imap.php on line 189
Notice: Uninitialized string offset: 0 in /vendor/zendframework/zend-mail/src/Protocol/Imap.php on line 194
Notice: Uninitialized string offset: 0 in /vendor/zendframework/zend-mail/src/Protocol/Imap.php on line 201
Notice: Uninitialized string offset: -1 in /vendor/zendframework/zend-mail/src/Protocol/Imap.php on line 221
array (
0 =>
array (
0 => '3596',
1 => 'FETCH',
2 =>
array (
0 => 'ENVELOPE',
1 =>
array (
0 => 'Mon, 07 Apr 2014 08:32:39 +0000',
1 => 'Igor Presnyakov: \\',
2 => 'Kansas',
3 => '-',
4 => 'Dust',
5 => 'In',
6 => 'The',
7 => 'Wind',
8 =>
array (
0 => '',
1 => 'guitar&vocal',
2 => 'edition',
),
9 => '-',
10 => 'Igor',
11 => 'Presnyakov\\""',
12 =>
array (
0 =>
array (
0 => 'YouTube',
1 => 'NIL',
2 => 'noreply',
3 => 'youtube.com',
),
),
13 =>
array (
0 =>
array (
0 => 'YouTube',
1 => 'NIL',
2 => 'noreply',
3 => 'youtube.com',
),
),
14 =>
array (
0 =>
array (
0 => 'YouTube',
1 => 'NIL',
2 => 'noreply',
3 => 'youtube.com',
),
),
15 =>
array (
0 =>
array (
0 => 'My Name',
1 => 'NIL',
2 => 'username',
3 => 'gmail.com',
),
),
16 => 'NIL',
17 => 'NIL',
18 => 'NIL',
19 => '<****@google.com>',
),
),
),
)
*** Expected ZEND response
array (
0 => 'Mon, 07 Apr 2014 08:32:39 +0000',
1 => 'Igor Presnyakov: \\"Kansas - Dust In The Wind ( guitar&vocal edition ) - Igor Presnyakov\\"',
2 =>
array (
0 =>
array (
0 => 'YouTube',
1 => 'NIL',
2 => 'noreply',
3 => 'youtube.com',
),
),
3 =>
array (
0 =>
array (
0 => 'YouTube',
1 => 'NIL',
2 => 'noreply',
3 => 'youtube.com',
),
),
4 =>
array (
0 =>
array (
0 => 'YouTube',
1 => 'NIL',
2 => 'noreply',
3 => 'youtube.com',
),
),
5 =>
array (
0 =>
array (
0 => 'My Name',
1 => 'NIL',
2 => 'username',
3 => 'gmail.com',
),
),
6 => 'NIL',
7 => 'NIL',
8 => 'NIL',
9 => '<****@google.com>',
)
*** Managed to parse response with the help of: https://github.com/petewarden/handmadeimap
Thanks!
TLDR; Check in all files that codeblocks are correct, in PSR-2 format and have PHP syntax highlighting applied.
Code blocks should be in the following format...
```php 'ZEND-FRAMEWORK'); // No required options $rendererOptions = array(); $renderer = Barcode::factory( 'code39', 'image', $barcodeOptions, $rendererOptions ); ```
Note the three backticks then php in the opening fence, and the closing fence is just three backticks. It's common for the opening backticks to have no code type, or something like source.
Code should also have been automatically formatted into PSR-2 format, but sometimes these slip through the net.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.