Reputation: 51
I have three problems with my mails sended by Zend Framework 2.
First of all, the subject appears twice with a comma. For example, if a set "My subject", the subject in Outlook or Gmail will be "My subject, my subject". Why it does that and how can I fix that?
After that, There is always an "UTF-8" written before the text of my mails. How can I remove that?
Finally, all my accents are replaced by "C) or )c". And yet, I set UTF-8.
I tested in Outlook and Gmail. All these errors are the same for Outlook and Gmail.
Thanks.
My code:
use Zend\Mail\Message;
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part as MimePart;
use Zend\Mail\Transport\Sendmail as SendmailTransport;
.
.
.
$message = new Message();
$bodyPart = new \Zend\Mime\Message();
$bodyMessage = new \Zend\Mime\Part($emailTemplate);
$bodyMessage->type = 'text/html';
$bodyPart->setParts(array($bodyMessage));
$message->setEncoding("UTF-8")
->addFrom("$from")
->addTo("$courrielDestinataire")
->setSubject($contactObject->sujet)
->setBody($bodyPart);
$transport = new SendmailTransport();
$transport->send($message);
Upvotes: 1
Views: 494
Reputation: 5311
For your question
In ZF2 subject appears twice with a comma. For example, if a set "My subject", the subject in Outlook or Gmail will be "My subject, my subject".
When sending an email with the default Zend mailer, the subject headers are added two times. This is because the header is set by the PHP mail() function, and is not removed from the additional headers if the server is Windows machine. This was fixed with issue ZF2-177 but only for *nix machines.
check this isssue http://framework.zend.com/issues/browse/ZF2-177
Upvotes: 0
Reputation: 51
When I removed this from my emailTemplate and the «UTF-8» didn't show in my email, but I don't know why.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
However I didn't fix my two other problems. I make a var_dump($message->getSubject()) and it dump show my subject correctly.
I changed my code for this and fixed all my problems, but it's not ZF2
$headers = "Content-Type: text/html; charset=\"UTF-8\"";
mail("$courrielDestinataire","$contactObject->sujet","$emailTemplate",$headers);
Thanks for your help though.
Upvotes: 2