My server sends a routine email to a list of people every now and then. I'd like to be bale to send it as HTML. I know I need to use $headers .= "Content-Type: text/html; charset=ISO-8859-1 ";
or something like that, however I also use a little plugin I found a while back that allows me to connect to the SMTP server before sending the mail (so it doesn't come up as spam in inboxes and what not).
Anyway, anyone know how I can edit the plugin to make it send as HTML?
Mailing script:
include('SMTPconfig.php');
include('SMTPClass.php');
$emailbody='I\'d like this to send as html';
$elist = mysql_query("SELECT email FROM `subs` ORDER BY id ASC");
if(mysql_num_rows($elist) > 0)
{
while($elist_result = mysql_fetch_array($elist))
{
$to= $elist_result['email'];
$from = 'admin@chloecrayola.co.uk';
$subject = $_POST['sub'];
$body = $emailbody;
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
exit();
}
Config file:
$SmtpServer="mail.chloecrayola.co.uk";
$SmtpPort="25";
$SmtpUser="admin@chloecrayola.co.uk";
$SmtpPass="*******";
And finally, the bit that sends the emails. I need to make changes here, but I don't know how I'd do it:
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "")
{
$this->PortSMTP = 25;
}else{
$this->PortSMTP = $SmtpPort;
}
}
function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."
");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login
");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."
");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."
");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">
");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">
");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA
");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">
From: <".$this->from.">
Subject:".$this->subject."
".$this->body."
.
");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT
");
fclose($SMTPIN);
}
return $talk;
}
}
I'm sure it must be possible to do, but I literally have no clue. Thanks
Content-Type: multipart/alternative;
boundary="===boundaryString=="
MIME-Version: 1.0
Try to use the above MIME header in $headers.
Then the body needs to include the following:
--===boundaryString==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
...
text template
...
--===boundaryString==
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
...
html template
...
It is always a good practice to include both txt and html templates containing the same information formatted as txt and as HTML. Helps avoiding the spam filters and improves the overall delivery. Still this is not a substitute for a proper reverse lookup setup which includes SPF, DKIM, DMARK records on your DNS server.