将 html 模板添加到 swift 电子邮件正文
Adding html template to swift email body
我是 swiftmailer 的新手,我可以使用它成功发送电子邮件。我需要在电子邮件正文中添加一个 html 模板。我不确定该怎么做?
这是我用来
的代码
function sendMail($destinationEmail){
// Create the mail transport configuration
$transport = Swift_MailTransport::newInstance();
$html = "<html>
<head>
<title>Alerting System</title>
<style type=\"text/css\">
<!--
table {
font-family: Verdana, Arial, Helvetica, sans-serif;
border: thin solid;
}
th {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #f0f0f0;
background-color: #ff0000;
font-size: 12px;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000000;
font-size: 10px;
border: thin solid;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
<head>
<body>
<CENTER>
<TABLE width=\"50%\">
<TBODY>
<tr>
<th >test</th>
</tr>
</TBODY>
</TABLE>
<br>
Alerting and Reporting System
</CENTER></BODY></HTML>
";
// Create the message
$message = Swift_Message::newInstance();
$message->setTo(array(
$destinationEmail => "test",
$destinationEmail => "test mail"
));
$message->setSubject("This email is sent using Swift Mailer");
$message->setBody("You're our best client ever.");
$message->setFrom("test@testcom.com", "Alerts");
$message->attach($html, "text/html");
// Send the email
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
}
如何将这个 $html 变量添加到电子邮件模板中?任何建议将不胜感激。
使用这个
$html = "<html>
<head>
<title>Alerting System</title>
<style type=\"text/css\">
<!--
table {
font-family: Verdana, Arial, Helvetica, sans-serif;
border: thin solid;
}
th {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #f0f0f0;
background-color: #ff0000;
font-size: 12px;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000000;
font-size: 10px;
border: thin solid;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
<head>
<body>
<CENTER>
<TABLE width=\"50%\">
<TBODY>
<tr>
<th >test</th>
</tr>
</TBODY>
</TABLE>
<br>
Alerting and Reporting System
</CENTER></BODY></HTML>
";
$message->setBody($html,'text/html' // Mark the content-type as HTML);
我是 swiftmailer 的新手,我可以使用它成功发送电子邮件。我需要在电子邮件正文中添加一个 html 模板。我不确定该怎么做? 这是我用来
的代码 function sendMail($destinationEmail){
// Create the mail transport configuration
$transport = Swift_MailTransport::newInstance();
$html = "<html>
<head>
<title>Alerting System</title>
<style type=\"text/css\">
<!--
table {
font-family: Verdana, Arial, Helvetica, sans-serif;
border: thin solid;
}
th {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #f0f0f0;
background-color: #ff0000;
font-size: 12px;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000000;
font-size: 10px;
border: thin solid;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
<head>
<body>
<CENTER>
<TABLE width=\"50%\">
<TBODY>
<tr>
<th >test</th>
</tr>
</TBODY>
</TABLE>
<br>
Alerting and Reporting System
</CENTER></BODY></HTML>
";
// Create the message
$message = Swift_Message::newInstance();
$message->setTo(array(
$destinationEmail => "test",
$destinationEmail => "test mail"
));
$message->setSubject("This email is sent using Swift Mailer");
$message->setBody("You're our best client ever.");
$message->setFrom("test@testcom.com", "Alerts");
$message->attach($html, "text/html");
// Send the email
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
}
如何将这个 $html 变量添加到电子邮件模板中?任何建议将不胜感激。
使用这个
$html = "<html>
<head>
<title>Alerting System</title>
<style type=\"text/css\">
<!--
table {
font-family: Verdana, Arial, Helvetica, sans-serif;
border: thin solid;
}
th {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #f0f0f0;
background-color: #ff0000;
font-size: 12px;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000000;
font-size: 10px;
border: thin solid;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
<head>
<body>
<CENTER>
<TABLE width=\"50%\">
<TBODY>
<tr>
<th >test</th>
</tr>
</TBODY>
</TABLE>
<br>
Alerting and Reporting System
</CENTER></BODY></HTML>
";
$message->setBody($html,'text/html' // Mark the content-type as HTML);