I am trying to send an email which contains multiple parts. This email gets displayed correctly on Gmail, Thunderbird but the same is not as expected on Outlook mail client. On Outlook mail client, the first part of the mail is displayed as the content while the rest of the parts are as an attachment (i.e. one attachment per part). Sample code snippets:
namespace MyProject\Service;
use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;
use Zend\Mail\Message;
use Zend\Mail\Transport\Sendmail;
class MailService
{
/**
* @throws \Exception
*/
public function sendMail() : void
{
$htmlPart1 = new MimePart('<html>
<body>
<table>
<tr><td>Test data 1</td></tr>
<tr><td>Test data 1</td></tr>
<tr><td>Test data 1</td></tr>
<tr><td>Test data 1</td></tr>
<tr><td>Test data 1</td></tr><tr>
<td>Test data 1</td></tr>
</table>
</body>
</html>');
$htmlPart1->type = 'text/html';
$htmlPart2 = new MimePart('<html>
<body>
<table>
<tr><td>Test data 2</td></tr>
<tr><td>Test data 2</td></tr>
<tr><td>Test data 2</td></tr>
<tr><td>Test data 2</td></tr>
<tr><td>Test data 2</td></tr><tr>
<td>Test data 2</td></tr>
</table>
</body>
</html>');
$htmlPart2->type = 'text/html';
$body = new MimeMessage();
$body->setParts(array($htmlPart1, $htmlPart2));
$mail = new Message();
$mail->setBody($body);
$mail->setFrom('[email protected]', 'Sender\'s name');
$mail->addTo(<SOME_OUTLOOK_EMAIL>, 'Name');
$mail->addTo(<SOME_GMAIL_EMAIL>, 'Name');
$mail->setSubject('TestSubject');
try{
$transport = new Sendmail();
$transport->send($mail);
} catch (\Exception $e){
throw $e;
}
}
}
In the above snippet, <SOME_OUTLOOK_EMAIL> = some existing outlook email and <SOME_GMAIL_EMAIL> = some existing gmail email.
Please note, the above snippet is developed using ZF2. We also had the same issues when we used ZF1 earlier in our project.
When we searched for the solution we came across ZF1 Issue reported but we could not identify yet the correct solution. In other words, is this something related to ZF mail libraries or its something related to exchange servers/mail client which can not be handled through the source code.
It would be really helpful if any one can help me to solve out my problem.