将html放在单独的文件中并在该文件中准备邮件正文是一个很好的做法
$body = $this->renderPartial('_mail_body.php' .[
'gender' => $this->gender,
'name' => $this->name,
]);
以及内容_mail_body。php将是这样的
<html>
<body>
<table cellpadding="0" cellspacing="0" align="center" width="672px" style="font-size:24px; text-align:center;">
<tr>
<td width="670px" align="center" style="border-left:1px solid #e0e0e0; border-right:1px solid #e0e0e0; font-size:24px; font-family:Arial, Helvetica, sans-serif; padding-top:47px;">
<table width="608px" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="178px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; border-right:1px solid #e0e0e0; padding:11px;">
Name
</td>
<td width="427px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;padding:11px; color:#4e4e4e;">
<?php echo $name;?>
</td>
</tr>
<tr>
<td width="178px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; border-right:1px solid #e0e0e0; padding:11px;">
Gender
</td>
<td width="427px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;padding:11px; color:#4e4e4e;">
<?php echo $gender;?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>