我是HTML的新手,我正在尝试使用表格附件在PHP中发送电子邮件,我能想到的最好的想法是:
$table = "<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<table>
<tr>
<th>Account</th>
<th>Credit used</th>
<th>Sent messages</th>
<th>Balance</th>
</tr>
<?php foreach ($statistics as $row) {
<tr>
<td>". $row["username"] ."</td>
<td>". $row["creditUsed"] ."</td>
<td>". $row["sentMessages"] ."</td>
<td>". $row["balance"] ."</td>
</tr>
}
?>
</body>
</html>
</table>";
这个工作正常,直到我添加循环,它被视为一个字符串,并给出错误Notice: Array to string conversion
我不知道如何让它工作
答案 0 :(得分:1)
在您的代码中使用引号是错误的。
尝试以适当的方式制作HTML结构: -
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<table>
<tr>
<th>Account</th>
<th>Credit used</th>
<th>Sent messages</th>
<th>Balance</th>
</tr>
<?php foreach ($statistics as $row) {?>
<tr>
<td><?php echo $row["username"];?></td>
<td><?php echo $row["creditUsed"];?></td>
<td><?php echo $row["sentMessages"];?></td>
<td><?php echo $row["balance"];?></td>
</tr>
}
?>
</body>
</html>
</table>
注意: -
确保页面扩展名必须为.php
而非.html
确保此页面上设置了$statistics
+非空+。 (也有一些价值)
由于您希望在PhpMailer
中使用它,请执行以下操作: -
$table =
"<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<table>
<tr>
<th>Account</th>
<th>Credit used</th>
<th>Sent messages</th>
<th>Balance</th>
</tr>";
<?php foreach ($statistics as $row) {
$table .= "<tr><td>". $row["username"] ."</td><td>". $row["creditUsed"] ."</td><td>". $row["sentMessages"] ."</td><td>". $row["balance"] ."</td></tr>";
}
?>
$table .= "</body></html></table>";
答案 1 :(得分:1)
最好在HTML中使用以下结构:
function getEventData(dentistId) {
alert(dentistId);
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.CalendarController.eventData}', dentistId,
function(result, event){
if (event.status) {
evt = JSON.parse(result);
console.log(evt);
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listDay',
},
eventClick: function (calEvent, jsEvent, view) {
if(calEvent.editable === true) {
var start = moment(calEvent.start).format('YYYY-MM-DD HH:mm:ss');
var end = moment(calEvent.end).format('YYYY-MM-DD HH:mm:ss');
jQuery('[id$=startStringField]').val(start);
jQuery('[id$=endStringField]').val(end);
passToController();
} else {
return false;
}
},
eventOverlap: false,
defaultDate: $('#calendar').fullCalendar('today'),
navLinks: true,
events: evt,
eventRender: function(event, element) {
element.qtip({
content: event.description
});
},
textColor: 'white',
height:650,
})
} else if (event.type === 'exception') {
console.log(event.message);
} else {
console.log(event.message);
}
},
{escape: false}
);
}