Question

I am trying to make the body of the mail with this [huge concatenation]

$body='<table  border=1>'.'<tr>'.'<th>Description</th>'.'<th>Quantity</th>'.'<th>Cost</th>'.'</tr>';
for($x=0;$x<=$length-1;$x++)
    {
    $body .='<tr>'.'<td>'.$json2[$x]["description"].'</td>'.'<td>'.$json2[$x]["qty"].'</td>'.'<td>'.$json2[$x]["cost"].'</td>'.'</tr>';
    }

$body.='</table>';

And send it using Swift Mailer

$message = Swift_Message::newInstance('Thanks for your Order')
->setFrom(array('abc@gmail.com' => 'Sender')) 
->setTo(array('xzy@gmail.com' => 'Receiver Name')) 
->setBody($body,'html');

The mail is received successfully but I the table is not seen.

For Feroz

 $mailer = Swift_Mailer::newInstance($transport);
 $message = Swift_Message::newInstance('DialSwap - Thanks for your Order')
 ->setFrom(array('rorrykeys2@gmail.com' => 'DialSwap')) 
 ->setTo(array('rorrykeys@gmail.com' => 'Receiver Name')) 
 ->setBody($body,'text/html');
 $headers = $message->getHeaders();
 $headers->addTextHeader('Content-Type', 'text/html');
Was it helpful?

Solution

html is not a valid Content-Type:

->setBody($body,'html');

You probably want text/html.

You can find some usage examples in the Creating Messages chapter.

OTHER TIPS

you can add the headers like below

$message = Swift_Message::newInstance();

$headers = $message->getHeaders();

$headers->addTextHeader('Content-Type', 'text/html');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top