Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zend_Mail : html emails are not correct in php8.1 #274

Closed
svansteenkiste opened this issue Nov 14, 2022 · 17 comments
Closed

Zend_Mail : html emails are not correct in php8.1 #274

svansteenkiste opened this issue Nov 14, 2022 · 17 comments
Labels
to be released PR exists or in master, but not released yet
Milestone

Comments

@svansteenkiste
Copy link

When trying to send html email in php7.4, everything works fine, but when changing to php8.1, html is shown as plain text instead of well formatted html email

@hungtrinh
Copy link

Please provide a code snippet to reproduce it
or better please contribute test case like Zend_Mail_MailTest ::testGetJustBodyHtml()

@svansteenkiste
Copy link
Author

svansteenkiste commented Nov 15, 2022

Hi,

see snippet in attachment and result in image
snippet.txt
:
afbeelding

@hungtrinh
Copy link

hungtrinh commented Nov 15, 2022

Look like problem come from your mail reader client, Here it's result i test with mail server MailTrap, Run you code in php 8.1

DeepinScreenshot_select-area_20221115221148

<?php
$path = [
    __DIR__ . "/library",
    get_include_path()
];
set_include_path(implode(PATH_SEPARATOR, $path));

require_once  "Zend/Loader/Autoloader.php";
$autoloader = Zend_Loader_Autoloader::getInstance();
$html = '<!DOCTYPE html>
<html>
<body>
<h1>TEST MESSAGE</h1>
    <table width="100%" border="0" align="center" valign="top" cellpadding="0" cellspacing="0">


        <tbody>
            <tr>
                <td align="center" valign="top"><table width="650" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <td></td>
                            </tr>
                            <tr>
                                <td><br>
                                    <br></td>
                            </tr>
                            <tr>
                                <td align="center" valign="top"><img src="https://www.d-nailbar.be/OG_d-nailbar.jpg" height="150" alt="ALT Omschrijving"/></td>                                    
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td style="background-color: #64254f;" class="title">this is a title</td>
                            </tr>                                
                        </tbody>
                    </table></td>
            </tr>
        </tbody>
    </table>
</body>
</html>';

$tr = new Zend_Mail_Transport_Smtp('smtp.mailtrap.io', [
    'auth' => 'login',
    'username' => 'xxx',
    'password' => 'yyy',
    'port' => 465
]);
Zend_Mail::setDefaultTransport($tr);

$emailFrom = "[email protected]";
$emailTo = "[email protected]";
$mail = new Zend_Mail('UTF-8');
$mail->setBodyHtml($html);
$mail->setFrom($emailFrom, 'stijn');
$mail->addTo($emailTo);
$mail->setSubject('TEST koekoek');
$mail->send();

@svansteenkiste
Copy link
Author

well, this is most strange, because when i run this script in php7.4, it works fine.

@hungtrinh
Copy link

So which smtp server do you use Mr @svansteenkiste ?

@svansteenkiste
Copy link
Author

i'm using Zend/Mail/Transport/Sendmail.php

@hungtrinh
Copy link

Oops look like internal bug of php 8.x.

$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header);
restore_error_handler();

Reference:

@svansteenkiste
Copy link
Author

i modified this on line 106:

str_replace("\n", "\r\n", $this->header);

Mail is now ok !
I think it has something to do with LF characters from mail headers

@svansteenkiste
Copy link
Author

Thx for pointing me the right direction ;-)

@hungtrinh
Copy link

You’re welcome

@jakubprokopec
Copy link

@svansteenkiste It's the Zend\Mail\Transport\Abstract and

/**
 * EOL character string used by transport
 * @var string
 * @access public
 */
public $EOL = "\r\n";

Just in case you didn't found the exact problem yet.

@svansteenkiste
Copy link
Author

@jakubprokopec indeed, but in Zend\Mail\Transport\Sendmail you also have this
/**
* EOL character string
* @var string
* @access public
*/
public $EOL = PHP_EOL;

maybe better to remove here?

@jakubprokopec
Copy link

@svansteenkiste Totally... Thank you!

@ToonSpinISAAC
Copy link

FYI we have found that this issue may cause AWS Simple Email Service (SES) to reject mail with the message: "554 Transaction failed: Nested group".

Just commenting this in the hopes that someone stumbles upon this when trying to Google it, because that particular error message is not easy to Google.

@ADDISON74
Copy link

From what I can see, those who faced this issue chose to make individual changes in the ZF1-Future file. May I ask why a PR was not pushed to fixe the issue for the others who have not faced it yet? In a test configuration I managed to reproduce this problem with all the email messages sent by OpenMage.

@develart-projects
Copy link
Collaborator

Scheduled for 1.23.0 release, awaiting 2 more PRs resp. PR owners to take some action.

@develart-projects develart-projects added this to the 1.23.0 milestone Aug 9, 2023
@develart-projects develart-projects added the to be released PR exists or in master, but not released yet label Aug 9, 2023
@develart-projects
Copy link
Collaborator

1.23.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to be released PR exists or in master, but not released yet
Projects
None yet
Development

No branches or pull requests

6 participants