在HTML邮件中使用PHP循环
我有一个php mail()可以正常工作。但是,当我试图在HTML内容中添加for循环以在需要时复制数据时,它只会给出一封空白邮件 我的代码如下:在HTML邮件中使用PHP循环,php,Php,我有一个php mail()可以正常工作。但是,当我试图在HTML内容中添加for循环以在需要时复制数据时,它只会给出一封空白邮件 我的代码如下: $to = $email; $from = 'frommail@gmail.com'; $fromName = 'site name'; $subject = "subject goes here"; $htmlContent = ' <table w
$to = $email;
$from = 'frommail@gmail.com';
$fromName = 'site name';
$subject = "subject goes here";
$htmlContent = ' <table width="640" cellspacing="0" cellpadding="0" border="0" align="left" style="vertical-align: central; background: white;">
<tbody>
<tr>
'; for($num = 1; $num <= 3; $num++) { '
<td width="30%" bgcolor="#ffffff" align="left" style="font: 13px Arial, sans-serif; text-decoration: none; vertical-align: top; padding: 6px 16px 0 6px; line-height: 18px;">
<table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">
<tbody>
<tr>
<td valign="bottom" align="left" style="vertical-align: left; padding: 4px 6px 4px 6px;">
<a href="" target="_blank" data-saferedirecturl="">
<img
src="https://ci5.googleusercontent.com/proxy/zZrFmHNgHyBIZxLE-YgAoaSXo3azfzJOrKm6F_o7OrDOzp9-bCDcU6ycfbAHWRHUBWPkJDu33r2UcOn7iTZ4KiMnw2ukGVh3CMLatAX1kg-hF1hIeKt9WFSukKfN_wKZHkE=s0-d-e1-ft#https://images-eu.ssl-images-amazon.com/images/I/81PeG59W8fL._AC_SR115,115_.jpg"
width="115"
height="115"
alt="Bourge Mens Loire-99 Running Shoes"
border="0"
class="CToWUd"
/>
</a>
</td>
</tr>
<tr align="left" style="padding: 0; display: block; line-height: 16px;">
<td align="left">
<span style="font: 13px Arial, sans-serif; text-decoration: none; color: #868686;">
<a
href="https://www.amazon.in/gp/r.html?C=I16HQS27WPED&K=3UKDG356NSZ9O&M=urn:rtn:msg:202007280401268c0c8b33b2024157b4ff1cfed740p0eu&R=14QEUUMSABYUR&T=C&U=https%3A%2F%2Fwww.amazon.in%2Fgp%2Fproduct%2FB07QLYVBD5%2Fref%3Dpe_3025041_189395861_pd_te_s_mr_ti%3F_encoding%3DUTF8%26pd_rd_i%3DB07QLYVBD5%26pd_rd_r%3DKCVKENDXQHECNTMTBWK7%26pd_rd_w%3DjGq5W%26pd_rd_wg%3DlS1ag&H=1KJFSIL6U5VSBGX1K9KQZ3Z8KKEA&ref_=pe_3025041_189395861_pd_te_s_mr_ti"
style="font: 13px Arial, sans-serif; text-decoration: none; color: #868686;"
target="_blank"
data-saferedirecturl="https://www.google.com/url?q=https://www.amazon.in/gp/r.html?C%3DI16HQS27WPED%26K%3D3UKDG356NSZ9O%26M%3Durn:rtn:msg:202007280401268c0c8b33b2024157b4ff1cfed740p0eu%26R%3D14QEUUMSABYUR%26T%3DC%26U%3Dhttps%253A%252F%252Fwww.amazon.in%252Fgp%252Fproduct%252FB07QLYVBD5%252Fref%253Dpe_3025041_189395861_pd_te_s_mr_ti%253F_encoding%253DUTF8%2526pd_rd_i%253DB07QLYVBD5%2526pd_rd_r%253DKCVKENDXQHECNTMTBWK7%2526pd_rd_w%253DjGq5W%2526pd_rd_wg%253DlS1ag%26H%3D1KJFSIL6U5VSBGX1K9KQZ3Z8KKEA%26ref_%3Dpe_3025041_189395861_pd_te_s_mr_ti&source=gmail&ust=1596092101507000&usg=AFQjCNHNa6zlhX3HN9z7bHYgdFFUaOEZkQ"
>
Bourge Mens Loire-99 Running Shoes
</a>
</span>
</td>
</tr>
<tr align="left" style="padding: 0; display: block; line-height: 16px;">
<td valign="middle" align="left">
<span style="font: 13px Arial, sans-serif; text-decoration: none; color: #868686; vertical-align: 3px;"> Rs. 629.00 </span>
<span style="vertical-align: 0px;"></span>
</td>
</tr>
</tbody>
</table>
</td>
'; } '
</tr>
</tbody>
</table>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n";
if(mail($to, $subject, $htmlContent, $headers)){
header("location:index?alert=mailsent");
}else{
header("location:index");
}
$to=$email;
$fromfrommail@gmail.com';
$fromName=‘站点名称’;
$subject=“subject在这里”;
$htmlContent='1!'
'; 对于($num=1;$num您需要将for循环中的字符串连接到$htmlContent
。。。
$htmlContent='。。。;
对于($num=1;$num对于($num=1;$num),您只是在循环中创建输出,它将直接添加到输出缓冲区,并分别发送到客户端。您需要继续将其连接到变量$htmlContent。
...
$htmlContent = '<table>...<tr>;
for($num = 1; $num <= 3; $num++) {
$htmlContent .= '<td>...</td>';
}
$htmlContent .= '</tr></tbody></table>';
...