UTF-8 Accents not been well displayed in HTML email with PHPMailer - php

I'm setup a PHPMailer PHP Form that send us the form to our Office 365 account. Im having issue with French accents displayed has "ééé à à à çç" accents like "éé àà çç".
PHP Form are encoded in UTF-8;
PHP Code are also encoded in UTF-8;
But the email received seems to not show the proper characters.
I have add theses settings and nothing has changed :
In the PHP file
header('Content-Type: charset=utf-8');
Also
$mail->isHTML(true); // Set email format to HTML
$mail->CharSet = "UTF-8";
Php Sending Form Source Code:
<?php
header('Content-Type: charset=utf-8');
ini_set('startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'php/phpmailer/vendor/phpmailer/phpmailer/src/Exception.php';
require 'php/phpmailer/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'php/phpmailer/vendor/phpmailer/phpmailer/src/SMTP.php';
$nom_compagnie = $_POST['nom_compagnie'];
$nom_complet = $_POST['nom_complet'];
$poste = $_POST['poste'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$commentaire = $_POST['commentaire'];
$from = $_POST['email'];
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => 'PrivateKey',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the reCAPTCHA is not properly set up
echo 'reCAPTCHA error: Check to make sure your keys match the registered domain and are in the correct locations. You may also want to doublecheck your code for typos or syntax errors.';
} else {
// If CAPTCHA is successful...
try {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'EmailAccount';
$mail->Password = 'Password';
$mail->addReplyTo($from, $nom_complet);
$mail->SetFrom ("Hidden", "Hidden");
$mail->addCC ("Hidden", "Hidden");
$mail->addAddress ('Hidden', 'Hidden);
//$mail->SMTPDebug = 3;
//$mail->Debutoutput = fonction($str, $level) {echo "debug level $level; message: $str";}; //
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "FORMULAIRE CONTACT";
$mail->Body = "
<html>
<head>
<meta charset=\"UTF-8\">
<title>Formulaire de Contact</title>
....
</html>";
$mail->AltBody = "";
$mail->CharSet = "UTF-8";
//$mail->msgHTML(file_get_contents('email_form_contact-fr.html'));
$mail->send();
// Paste mail function or whatever else you want to happen here!
} catch (Exception $e) {
echo $e->getMessage();
die(0);
}
header('Location: envoi_form_contact-success-fr.html');
}
?>
The email received has shown like this :
The H3 title in the email are shown
Vous avez reçu un formulaire de contact via le site Web
It supposed to be written like this
Vous avez reçu un formulaire de contact via le site web
Accent "é" are also displayed has "é".
I don't know where is the problem.
Any clue if my code are well programmed?
Thanks.

Replace
$mail -> charSet = "UTF-8";
with
$mail->CharSet = 'UTF-8';

Bonjour Stéphane. This page describes the symptom you are seeing; one character turning into two means that your data is in UTF-8, but is being displayed using an 8-bit character set. Generally speaking, PHPMailer gets this right, so you need to figure out where you are going wrong.
If you use SMTPDebug = 2 you will be able to see the message being sent (use a really short message body like é😎 that is guaranteed to only work in UTF-8).
Make sure that the encoding of the script file itself is also UTF-8 - putting an emoji in it is a good way of being sure that it is.
The problem with diagnosing this is that you'll find your OS interferes - things like copying to the clipboard are likely to alter encodings - so the way to deal with it is to use a hex dump function that lets you inspect the actual byte values. French is one of the easier ones to look at because nearly all characters will be regular single-byte ASCII-compatible characters, and accented characters will be easier to spot. In PHP the bin2hex() function will do this.
You have 2 typos: Debutoutput should be Debugoutput and fonction should be function - and that is a good place to dump hex data from:
$mail->Debugoutput = function($str, $level) {echo $str, "\n", bin2hex($str), "\n";};
Here's an example:
echo 'abc ', bin2hex('abc');
which will produce abc 616263; each input char results in 2 hex digits (1 byte) of output. If your input is abé and your charset is ISO-8859-1, it will come out as abé 6162e9, because é in that charset is e9 (in hex). The same string in UTF-8 would come out as abé 6162c3a9, because é in UTF8 is c3a9 - two bytes, not just one. Inspecting the characters like this allows you to be absolutely certain what character set the data is in - just looking at it is not good enough!
So, while I can't tell exactly where your problem is, hopefully you have some better ideas of how to diagnose it.

Related

PHP: Sending Email with Cyrillic (Ukrainian text)

Problem with sending Cyrillic Email with PHP.
My side:
Server IIS - Database MsSQL - email server: Exchange 2010 /communication via PHP EWS/
Reciever is UA Goverment owned company with their specific software for receiving emails. It is working with MS Outlook /manually send/.
I tried send it as text /not html/ or i tried PHP Mailer, i also already tried with C# /all are not working with this specific company /on gmail or hotmail it's working fine//.
$ews = new ExchangeWebServices($server, $username, $password);
$msg = new EWSType_MessageType();
$toAddresses = array();
$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress =;
$toAddresses[0]->Name =;
$msg->ToRecipients = $toAddresses;
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress =;
$fromAddress->Name =;
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = "Test";
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML'; //Text HTML
$msg->Body->_ = $UAText;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $ews->CreateItem($msgRequest);
var_dump($response);
Thank You,
If its working with an normal Outlook client, however not with your solution my first check would be to compare the header from two example emails (one from outlook and one from your solution). I think that the content-type is set correctly with Outlook however not with your solution.
So you might wish to set the content encoding to UTF-8 in your solution. So I assume the content inside $UAText is some HTML stuff. You might therefore wish to flag that part as UTF-8 via:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
and see how it works.
Additional you might wish to set the encoding directly inside your code via:
$ews = new ExchangeWebServices($host, $user, $password, ExchangeWebServices::VERSION_2007_SP1);
$msg = new EWSType_MessageType();
$msg->MimeContent = new EWSType_MimeContentType();
$msg->MimeContent->_ = base64_encode("Mime-Version: 1.0\r\n"
. "From: michael#contoso.com\r\n"
. "To: amy#contoso.com\r\n"
. "Subject: nothing\r\n"
. "Date: Tue, 15 Feb 2011 22:06:21 -0000\r\n"
. "Message-ID: <{0}>\r\n"
. "X-Experimental: some value\r\n"
. "\r\n"
. "I have nothing further to say.\r\n");
$msg->MimeContent->CharacterSet = 'UTF-8';
Note: Here is a good starting point regarding the content-type encoding option. You also might wish to check the official Microsoft howto here.

Weird E-Mail parsing error with Paypal Donation Mail

I want to automatically process E-Mails which I get from Paypal for donations to my E-Mail-Adress. (via cronjob and php script)
So far, so good. I made a test donation and for further testing, I copy this mail with Outlook to INBOX several times.
Everything worked fine with the copied Mail (I'm checking a String in E-Mail Body)
but now I've made another test donation and it wasn't working.
It turned out that the E-Mail-Body is not parsed correctly.
I've tried already with Ararat Synapse in Delphi but same result.
The correct E-Mail Body from copied Mail looks like this:
Guten Tag Peter Meier ! Diese E-Mail bestätigt den Erhalt einer Spende über €1,50 EUR von Peter Meier (peter.meier#gmx.de ). Sie können die Transaktionsdetails online abrufen . Spendendetails Gesamtbetrag: €1,50 EUR
But the original Mail from Paypal is parsed as
PGh0bWwgPgogICA8aGVhZD4KICAgCQk8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUi IGNvbnRlbnQ9InRleHQvaHRtbDsgY2hhcnNldD1VVEYtOCI+CiAgIAkJPG1ldGEgbmFtZT0i dmlld3BvcnQiIGNvbnRlbnQ9ImluaXRpYWwtc2NhbGU9MS4wLG1pbmltdW0tc2NhbGU9MS4w LG1heGltdW0tc2NhbGU9MS4wLHdpZHRoPWRldmljZS13aWR0aCxoZWlnaHQ9ZGV2aWNlLWhl aWdodCx0YXJnZXQtZGVuc2l0eWRwaT1kZXZpY2UtZHBpLHVzZX...
And so on, copiedmail.html is 3KB, original is 28KB.
My Code:
$connection = imap_open("{imap.gmx.net:993/imap/ssl}", "peter.meier#gmx.de", "password"); //connect
$count = imap_num_msg($connection); //get E-Mail count in INBOX
for($msgno = 1; $msgno <= $count; $msgno++) //walk through INBOX mails
{
$headers = imap_headerinfo($connection, $msgno); //read E-Mail header
$subject = $headers->subject; //read subject
//decode subject
$elements = imap_mime_header_decode($subject);
$decodedsubject="";
for ($i=0; $i<count($elements); $i++)
{
$decodedsubject = $decodedsubject.$elements[$i]->text;
}
$body = imap_fetchbody ($connection, $msgno, 1); //read body
echo $body; <--- Here I get long cryptic Text in original Mail
}
Thanks to NineBerry,
I found out that paypal uses base64 encoding for their mails.
So the body was parsed correctly by this code
$body = imap_fetchbody ($connection, $msgno, 1); //read E-Mail-Body
$body = imap_base64($body);
echo $body;
To check encoding as suggested, you could do:
$structure = imap_fetchstructure($connection, $msgno);
$encoding = $structure->encoding;
$body = imap_fetchbody ($connection, $msgno, 1);
$body=decodebody($encoding, $body);
echo $body;
function decodebody($encoding, $body)
{
switch ($encoding)
{
# 7BIT
case ENC7BIT:
echo "7BIT<br>";//
return $body;
break;
# 8BIT
case ENC8BIT:
echo "8BIT<br>";//
return quoted_printable_decode(imap_8bit($body));
break;
# BINARY
case ENCBINARY:
echo "BINARY<br>";//
return imap_binary($body);
break;
# BASE64
case ENCBASE64:
echo "BASE64<br>";//
return imap_base64($body);
break;
# QUOTED-PRINTABLE
case ENCQUOTEDPRINTABLE:
echo "QUOTED<br>";//
return quoted_printable_decode($body);
break;
# OTHER
case ENCOTHER:
echo "OTHER<br>";//
return $body;
break;
# UNKNOWN
default:
echo "UNKNOWN<br>";//
return $body;
break;
}
}
Of course echo in function is only for you to check.
BTW, I pasted the snippet from my Original Question to this online decoder:
https://www.base64decode.org and it also worked :)

utf-8 charset not working on contact form with PEAR Mail_mime

I've found and tried various solutions given in other questions about utf-encoding for special characters and other related problems, but without any success.
I have an html contact form that sends information to my mail address with a simple php script using PEAR Mail mime. I can send information containing special characters from my test site on localhost with no problems, but not after I uploaded to my server.
eg message:
Test special characters: é è ç à ô
after being sent from server becomes:
Test special characters: é è ç à ô
I am guessing it's an encoding problem from my web server, but am kinda stuck at how to resolve the problem.
The meta tags in file containing the form are set to:
<meta charset="utf-8">
and the form is specified to accept charset utf-8:
<form name="contact" method="post" action="assets/send_form.php" accept-charset="UTF-8">
I've also tried sending content from php file with:
header("Content-Type: text/html; charset= UTF-8");
as well as creating $headers for the message with 'Content-Type' = 'text/html; charset="UTF-8".
The relevant php code in my script:
//This section creates the email headers
$headerss=array();
$headerss['From']= $from_address;
$headerss['To']= $siteEmail;
$headerss['Subject']= $email_subject;
$headerss['Return-Path']= $contactEmail;
$headerss['Date']= date("r");
$headerss['Content-Type'] = 'text/html; charset="UTF-8"';
// This section creates the smtp inputs
$auth = array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password);
// create new Mail_mime instance, set utf-8 charset
$mail = new Mail_mime();
$mail -> setHTMLBody($email_message);
//CHECK THIS OUT FOR UTF-8 *****************************
$mimeparams=array();
$mimeparams['text_encoding']="7bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$mimeparams['head_charset']="UTF-8";
$mimeparams['eol']= "\n" ;
$body = $mail->get($mimeparams);
$headers = $mail->headers($headerss);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$sendmail = $smtp->send($siteEmail, $headers, $body);
Any help will be really appreciated. Thanks.
Try to put before
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I experienced the same problem and my solution was to save the php file in same format, in UTF-8 as I had saved in ANSI format. That solved my problem anyway.

Send Mail from raw body for testing purposes

I am developing a PHP application that needs to retrieve arbitrary emails from an email server. Then, the message is completely parsed and stored in a database.
Of course, I have to do a lot of tests as this task is not really trivial with all that different mail formats under the sun. Therefore I started to "collect" emails from certain clients and with different contents.
I would like to have a script so that I can send out those emails automatically to my application to test the mail handling.
Therefore, I need a way to send the raw emails - so that the structure is exactly the same as they would come from the respective client. I have the emails stored as .eml files.
Does somebody know how to send emails by supplying the raw body?
Edit:
To be more specific: I am searching for a way to send out multipart emails by using their source code. For example I would like to be able to use something like that (an email with plain and HTML part, HTML part has one inline attachment).
--Apple-Mail-159-396126150
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
The plain text email!
--=20
=20
=20
--Apple-Mail-159-396126150
Content-Type: multipart/related;
type="text/html";
boundary=Apple-Mail-160-396126150
--Apple-Mail-160-396126150
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=iso-8859-1
<html><head>
<title>Daisies</title>=20
</head><body style=3D"background-attachment: initial; background-origin: =
initial; background-image: =
url(cid:4BFF075A-09D1-4118-9AE5-2DA8295BDF33/bg_pattern.jpg); =
background-position: 50% 0px; ">
[ - snip - the html email content ]
</body></html>=
--Apple-Mail-160-396126150
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=bg_pattern.jpg
Content-Type: image/jpg;
x-apple-mail-type=stationery;
name="bg_pattern.jpg"
Content-Id: <4BFF075A-09D1-4118-9AE5-2DA8295BDF33/tbg.jpg>
/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAASAAA/+IFOElDQ19QUk9GSUxFAAEB
[ - snip - the image content ]
nU4IGsoTr47IczxmCMvPypi6XZOWKYz/AB42mcaD/9k=
--Apple-Mail-159-396126150--
Using PHPMailer, you can set the body of a message directly:
$mail->Body = 'the contents of one of your .eml files here'
If your mails contain any mime attachments, this will most likely not work properly, as some of the MIME stuff has to go into the mail's headers. You'd have to massage the .eml to extract those particular headers and add them to the PHPMailer mail as a customheader
You could just use the telnet program to send those emails:
$ telnet <host> <port> // execute telnet
HELO my.domain.com // enter HELO command
MAIL FROM: sender#address.com // enter MAIL FROM command
RCPT TO: recipient#address.com // enter RCPT TO command
<past here, without adding a newline> // enter the raw content of the message
[ctrl]+d // hit [ctrl] and d simultaneously to end the message
If you really want to do this in PHP, you can use fsockopen() or stream_socket_client() family. Basically you do the same thing: talking to the mailserver directly.
// open connection
$stream = #stream_socket_client($host . ':' . $port);
// write HELO command
fwrite($stream, "HELO my.domain.com\r\n");
// read response
$data = '';
while (!feof($stream)) {
$data += fgets($stream, 1024);
}
// repeat for other steps
// ...
// close connection
fclose($stream);
You can just use the build in PHP function mail for it. The body part doesnt have to be just text, it can also contain mixed part data.
Keep in mind that this is a proof of concept. The sendEmlFile function could use some more checking, like "Does the file exists" and "Does it have a boundry set". As you mentioned it is for testing/development, I have not included it.
<?php
function sendmail($body,$subject,$to, $boundry='') {
define ("CRLF", "\r\n");
//basic settings
$from = "Example mail<info#example.com>";
//define headers
$sHeaders = "From: ".$from.CRLF;
$sHeaders .= "X-Mailer: PHP/".phpversion().CRLF;
$sHeaders .= "MIME-Version: 1.0".CRLF;
//if you supply a boundry, it will be send with your own data
//else it will be send as regular html email
if (strlen($boundry)>0)
$sHeaders .= "Content-Type: multipart/mixed; boundary=\"".$boundry."\"".CRLF;
else
{
$sHeaders .= "Content-type: text/html;".CRLF."\tcharset=\"iso-8859-1\"".CRLF;
$sHeaders .= "Content-Transfer-Encoding: 7bit".CRLF."Content-Disposition: inline";
}
mail($to,$subject,$body,$sHeaders);
}
function sendEmlFile($subject, $to, $filename) {
$body = file_get_contents($filename);
//get first line "--Apple-Mail-159-396126150"
$boundry = $str = strtok($body, "\n");
sendmail($body,$subject,$to, $boundry);
}
?>
Update:
After some more testing I found that all .eml files are different. There might be a standard, but I had tons of options when exporting to .eml. I had to use a seperate tool to create the file, because you cannot save to .eml by default using outlook.
You can download an example of the mail script. It contains two versions.
The simple version has two files, one is the index.php file that sends the test.eml file. This is just a file where i pasted in the example code you posted in your question.
The advanced version sends an email using an actual .eml file I created. it will get the required headers from the file it self. Keep in mind that this also sets the To and From part of the mail, so change it to match your own/server settings.
The advanced code works like this:
<?php
function sendEmlFile($filename) {
//define a clear line
define ("CRLF", "\r\n");
//eml content to array.
$file = file($filename);
//var to store the headers
$headers = "";
$to = "";
$subject = "";
//loop trough each line
//the first part are the headers, until you reach a white line
while(true) {
//get the first line and remove it from the file
$line = array_shift($file);
if (strlen(trim($line))==0) {
//headers are complete
break;
}
//is it the To header
if (substr(strtolower($line), 0,3)=="to:") {
$to = trim(substr($line, 3));
continue;
}
//Is it the subject header
if (substr(strtolower($line), 0,8)=="subject:") {
$subject = trim(substr($line, 8));
continue;
}
$headers .= $line . CRLF;
}
//implode the remaining content into the body and trim it, incase the headers where seperated with multiple white lines
$body = trim(implode('', $file));
//echo content for debugging
/*
echo $headers;
echo '<hr>';
echo $to;
echo '<hr>';
echo $subject;
echo '<hr>';
echo $body;
*/
//send the email
mail($to,$subject,$body,$headers);
}
//initiate a test with the test file
sendEmlFile("Test.eml");
?>
You could start here
http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/
I have no idea how good that code is, but it would make a starting point.
What you are doing is connecting direct to port 25 on the remote machine, as you would with telnet, and issuing smtp commands. See eg http://www.yuki-onna.co.uk/email/smtp.html for what's going on (or see Jasper N. Brouwer's answer).
Just make a quick shell script which processes a directory and call it when you want e.g. using at crontab etc
for I in ls /mydir/ do cat I | awk .. | sendmail -options
http://www.manpagez.com/man/1/awk/
You could also just talk to the mail server using the script to send the emls with a templated body..
Edit: I have added the code to Github, for ease of use by other people. https://github.com/xrobau/smtphack
I realise I am somewhat necro-answering this question, but it wasn't answered and I needed to do this myself. Here's the code!
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
class SMTPHack
{
private $phpmailer;
private $smtp;
private $from;
private $to;
/**
* #param string $from
* #param string $to
* #param string $smtphost
* #return void
*/
public function __construct(string $from, string $to, string $smtphost = 'mailrx')
{
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPAutoTLS = false;
$mail->Host = $smtphost;
$this->phpmailer = $mail;
$this->from = $from;
$this->to = $to;
}
/**
* #param string $helo
* #return SMTP
*/
public function getSmtp(string $helo = ''): SMTP
{
if (!$this->smtp) {
if ($helo) {
$this->phpmailer->Helo = $helo;
}
$this->phpmailer->smtpConnect();
$this->smtp = $this->phpmailer->getSMTPInstance();
$this->smtp->mail($this->from);
$this->smtp->recipient($this->to);
}
return $this->smtp;
}
/**
* #param string $data
* #param string $helo
* #param boolean $quiet
* #return void
* #throws \PHPMailer\PHPMailer\Exception
*/
public function data(string $data, string $helo = '', bool $quiet = true)
{
$smtp = $this->getSmtp($helo);
$prev = $smtp->do_debug;
if ($quiet) {
$smtp->do_debug = 0;
}
$smtp->data($data);
$smtp->do_debug = $prev;
}
}
Using that, you can simply beat PHPMailer into submission with a few simple commands:
$from = 'xrobau#example.com';
$to = 'fred#example.com';
$hack = new SMTPHack($from, $to);
$smtp = $hack->getSmtp('helo.hostname');
$errors = $smtp->getError();
// Assuming this is running in a phpunit test...
$this->assertEmpty($errors['error']);
$testemail = file_get_contents(__DIR__ . '/TestEmail.eml');
$hack->data($testemail);

Problem with character encoding on email sent via PHP?

Having some trouble sending properly formatted HTML e-mail from a PHP script. I am running PHP 5.3.0 and Apache 2.2.11 on Windows XP Professional.
The output looks like this:
Agent Summary for Support on Tuesday April 20 2010=20
Ext. Name Time Volume
137 Agent Name 01:27:25 1
138 =09 00:00:00 0
139 =09 00:00:00 0
You see the =20 and =09 in there? If you look at the HTML you also see = signs being turned into =3D. I figure this is a character encoding issue as I read the following at Wikipedia:
ISO-8859-1 and Windows-1252 confusion
It is very common to mislabel text data with the charset label ISO-8859-1, even though the data is really Windows-1252 encoded. In Windows-1252, codes between 0x80 and 0x9F are used for letters and punctuation, whereas they are control codes in ISO-8859-1. Many web browsers and e-mail clients will interpret ISO-8859-1 control codes as Windows-1252 characters in order to accommodate such mislabeling but it is not standard behaviour and care should be taken to avoid generating these characters in ISO-8859-1 labeled content.
This looks like the problem but I don't know how to fix. My code looks like this:
ob_start();
report_queue_summary($yesterday,$yesterday,$first_extension,$last_extension,$queue);
$body_report = ob_get_contents();
ob_end_clean();
$body_footer = "This is an automatically generated e-mail.";
$message = new Mail_mime();
$html = $body_header.$body_report.$body_footer;
$message->setHTMLBody($html);
$body = $message->get();
$extraheaders = array("From"=>"***redacted***","To"=>$recipient, "Subject"=>"Agent Summary for $yesterday [$queue]", "Content-type"=>"text/html; charset=iso-8859-1");
$headers = $message->headers($extraheaders);
# setup e-mail;
$host = "*********";
$port = "26";
$username = "*****";
$password = "*****";
# Send e-mail
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($recipient, $extraheaders, $body);
if (PEAR::isError($mail)) {
echo("" . $mail->getMessage() . "");
} else {
echo("Message successfully sent!");
}
Is the problem that I'm using output buffering?
The problem is that you need the following header:
Content-Transfer-Encoding: quoted-printable

Categories