我有一个表格,其中填写了名称和详细信息,我可以收集填写的详细信息并通过电子邮件发送数据。但是在表单中填写了一个字段,其中包含"评论"字段。
<?php
$sql = "SELECT * FROM comments WHERE id = no ";
$result = mysqli_query ($conn,$sql) or die (mysqli_error ());
$count = 1;
while ($row = mysqli_fetch_array ($result))
{?>
<tr>
<td valign="top" >
<label for="old_comments">comments <?php
echo $count
?>:</label>
</td>
<td style="
padding-bottom: 0px;">
<input type="text" name="old_comments" value="<?php echo $row ['updates']; ?> "
readonly maxlength="500" size="30" style=" width: 710px; ">
<br>
<span class="helptext" >Previous comments.</span>
</td>
</tr>
<?php
$count = $count + 1;
}
?>
会有很多评论,但这里只有一条最近的评论被插入到邮件中。我需要将数据库中的所有注释用于特定的帖子ID表插入邮件正文。我用来发送的PHP代码电子邮件:
<?php
if(isset($_POST['email'])) {
$email_to = mail@domain.com;
$email_subject = omments;
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
die();
}
// validation expected data exists
if(!isset($_POST['old_comments'])) {
}
$old_comments = $_POST['old_comments]; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Comments";
function clean_string($string)
{
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Previous Comments: ".clean_string($Comments)."\n\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<?php
}
?>
任何人都可以帮助这个。谢谢提前