gpt4 book ai didi

php - 如何在 php 中将 HTML 动态表作为邮件发送?

转载 作者:行者123 更新时间:2023-11-28 20:39:22 26 4
gpt4 key购买 nike

这里我有一个代码,例如从index.php获取数据,如果用户输入数据,它将显示像表格一样,并且应该通过电子邮件发送到一些预定义的邮件。但在这里我动态获取数据,我尝试使用 $_REQUEST 和 $_POST 两种方法来获取数据,但在邮件功能中我试图更改消息参数,但通过 php 标签,它没有接受并显示一些语法错误。

请查看此处的代码

<?php
$to="xxxxxxx@gmail.com";
$fn="Fisrt Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="xxxxx@xxx.com";
$subject = "Welcome to Website";

include('newsmtp/smtpwork.php');

?>
<?php

$message = 'Dear $firstName,


Your Welcome Message.'.'
<table border=1>

<tr>
<td>First Name:</td>
<td><?php $firstName=$_POST['firstname'];
echo $firstName;?></td>
</tr>

<tr>
<td>Last Name:</td>
<td><?php $lastname=$_POST['lastname'];
echo $lastname;?></td>

</tr>

<tr>

<td>Title:</td>
<td><?php $title=$_POST['title'];
echo $title;?></td>
</tr>

<tr>

<td>Address:</td>
<td><?php $address=$_POST['address'];
echo $address;?></td>
</tr>

<tr>

<td>Phone Number:</td>
<td><?php $phone=$_POST['phone'];
echo $phone;?></td>
</tr>


<tr>

<td>Course Name:</td>
<td><?php $course=$_POST['coursename'];
echo $course;?></td>

</tr>

<tr>

<td>Website:</td>
<td><?php $website=$_POST['website'];
echo $website;?></td>

</tr>

</table>

Thanks
xxxxxxxxxxxx
';
?>

最佳答案

尝试此方法,在 $message 变量外部的变量中分配发布的值,并在 $message 变量内打印该变量

$firstname  = $_POST['firstname'];
$lastname = $_POST['lastname'];
$title = $_POST['title'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$course = $_POST['course'];
$website = $_POST['website'];


$message = 'Dear '.$firstName.',
Your Welcome Message.'.'
<table border=1>
<tr>
<td>First Name:</td>
<td>'.$firstname.' </td>
</tr>
<tr>
<td>Last Name:</td>
<td>'.$lastname.'</td>
</tr>
<tr>
<td>Title:</td>
<td>'.$title.'</td>
</tr>
<tr>
<td>Address:</td>
<td>'.$address.'</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>'.$phone.'</td>
</tr>
<tr>
<td>Course Name:</td>
<td>'.$course.'</td>
</tr>
<tr>
<td>Website:</td>
<td>'.$website.'</td>
</tr>
</table>
Thanks
xxxxxxxxxxxx
';
?>




$to ="xxxxxxx@gmail.com";
$subject = "Welcome to Website";
$headers = 'From: xxxxxx <noreply@xxxxxxx.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\r\n";

$sent = @mail($to,$subject,$message,$headers);

if ($sent) {
return true;
} else {
return false;
}

还添加必要的 header 以发送 HTML 邮件,如 Vinoth Babu,Naveen 建议的

关于php - 如何在 php 中将 HTML 动态表作为邮件发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14706563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com