我刚刚开始学习PHP而我正试图通过电子邮件发送我的表格。我收到了电子邮件,但正文正在说Array
。我不知道从哪里开始,请帮忙。
这就是我的表格显示方式,以及那里的发送邮件功能
<form action="assign.php" method="post"><?php
if(is_array($result)){
echo '
<fieldset>
<legend>Assign Ticket</legend>
<div>Changes will affect updated rows only.</div>
<p></p>
<table width=auto cellpadding=1px cellspacing=0px border=1 align=center id=assign>
<thead>
<tr>';
// column comment from DB as column header
foreach($result[0] as $key => $val){
echo '<th align=center>'.$colcomments[$key].'</th>';
}
echo '
</tr>
</thead>
<tbody>';
foreach($result as $row => $info){
echo '<tr>';
foreach($info as $key => $val){
if($key=='id'){
echo '<td title="'.$colcomments[$key].'">'.$val.'.<input type="hidden" name="'.$key.'['.$info['id'].']" value="'.$val.'" id="rowid_'.$val.'" /></td>';
}
else {
echo '<td title="'.$colcomments[$key].'"><input type="text" name="'.$key.'['.$info['id'].']" value="'.$val.'" /></td>';
}
}
echo '</tr>';
}
echo '
</tbody>
</table>
</fieldset>';
if($result) {
$Body = "<html>\n"
. "<head>\n"
. "</head>\n"
. "<body>\n"
. $result
. "</body>\n"
. "</html>\n";
//Setting up Mail
$mail = new PHPMailer();
if (EMAIL_USE_SMTP) {
// Set mailer to use SMTP
$mail->IsSMTP();
//useful for debugging, shows full SMTP errors
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
// Enable SMTP authentication
$mail->SMTPAuth = EMAIL_SMTP_AUTH;
// Enable encryption, usually SSL/TLS
if (defined(EMAIL_SMTP_ENCRYPTION)) {
$mail->SMTPSecure = EMAIL_SMTP_ENCRYPTION;
}
// Specify host server
$mail->Host = EMAIL_SMTP_HOST;
$mail->Username = EMAIL_SMTP_USERNAME;
$mail->Password = EMAIL_SMTP_PASSWORD;
$mail->Port = EMAIL_SMTP_PORT;
} else {
$mail->IsMail();
}
$mail->From = EMAIL_FROM_ADDRESS;
$mail->FromName = EMAIL_FROM_NAME;
$mail->AddAddress('sample.test@domain.COM');
$mail->Subject = 'Ticket Assignment - ';
$mail->WordWrap = 100;
$mail->IsHTML(true);
$mail->Body = $Body;
$mail->Send();
}
}
?>
<fieldset>
<legend>Select Date</legend>
<div>Select Date from and Date to</div>
<p></p>
<input type="date" name="from" id="from" value="<?=$date['from']; ?>" />
<input type="date" name="to" id="to" value="<?=$date['to']; ?>" />
<div><input type="submit" value="Submit" /></div>
</fieldset>
</form>
这是我得到的smtp调试结果,
Notice: Array to string conversion in C:\*\assign.php on line 260
指的是这个,
. "</body>\n"
答案 0 :(得分:0)
我没有测试,但我想这段代码会修复你的问题试试吧
if($result) {
$Body = "<html>\n"
. "<head>\n"
. "</head>\n"
. "<body>\n"
.json_encode($result, JSON_PRETTY_PRINT).
. "</body>\n"
. "</html>\n";
答案 1 :(得分:0)
问题出在您的行中,紧接在260以上。 $结果 是一个数组,所以你不能将它与其他字符串连接起来。
你不能使用;
'<body>'.$result.'</body>'
你可以使用;
'<body>'.json_encode($result).'</body>'
(或将您的数组转换为字符串的任何其他函数)
我希望有帮助吗?
答案 2 :(得分:0)
这是通过使用函数修复的。
function two_dim_array_to_html_table($arr, $colcomments){
$ret = "<table border='1' width='auto' cellpadding='1px' cellspacing='0px' align='center'>\n";
$ret .= "\t<tr>\n";
foreach($arr[0] as $key => $val){
$ret .= "\t\t<th>".$colcomments[$key]."</th>\n";
}
$ret .= "\t</tr>\n";
foreach($arr as $row){
$ret .= "\t<tr>\n";
foreach($row as $column){
$ret .= "\t\t<td>".$column."</td>\n";
}
$ret .= "\t</tr>\n";
}
$ret .= "<table>\n";
return $ret;
}