ChainWay
ChainWay

Reputation: 133

PHPMailer:send HTML format

I need to use PHPMailer to send emails with html format,but my email has hundreds of lines with many html tags and inline css,even there are some php code in it.it look like this:

$message=<<<str
    //some html code
     hello {$name}.   //$name is a php variable
    //come html code
    //hunderd of lines
str;

now i think tee meesage that to be sent is too large,is there clean way to do this? or I want to know how you will send a html format email with so large body? sorry for my bad englis!thanks in advance!!

Upvotes: 0

Views: 520

Answers (2)

SpiderLinked
SpiderLinked

Reputation: 373

Is text...so in order to be "too large" ... it would need to have more than 1 mill lines... (from space the occupied point of view).

In order to send an email in the html format just add this headers to your existing ones:

  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=UTF-8 \r\n";

And store all your lines into a variable. (add the php variables using string concatenation or something similar)

Upvotes: 0

Moeed Farooqui
Moeed Farooqui

Reputation: 3622

Just an example

 $message = '<html><body><div style="background-color:#FFFFFF; padding:15px 15px 40px 65px;width:490px;margin:0 auto">';

 $message .= '<table cellspacing="0" cellpadding="0" border="0" style="margin-bottom:7px;"><tbody style="color:#000000;">';

 $message .= '<tr><td width="170"><label style="display:block;padding:5px 0 10px 0;width:170px;font-family:Arial, Helvetica, sans-serif;font-size:12px">Name :</label></td><td width="277" style="font-family:Arial, Helvetica, sans-serif;font-size:12px">&nbsp;&nbsp;'. $name.'</td></tr>';

In the end

$mail->MsgHTML($message);

Upvotes: 1

Related Questions