PHP发送HTML电子邮件
我正在创建一个应用程序,发送存储在数据库中的HTML电子邮件。我使用PHP动态创建一个下拉菜单,其中包含数据库中可用的每个模板的名称 html代码位于一个名为temp_html的列中,并存储了一个原始html,我试图将此代码添加到选项值中,如下所示:PHP发送HTML电子邮件,php,html,Php,Html,我正在创建一个应用程序,发送存储在数据库中的HTML电子邮件。我使用PHP动态创建一个下拉菜单,其中包含数据库中可用的每个模板的名称 html代码位于一个名为temp_html的列中,并存储了一个原始html,我试图将此代码添加到选项值中,如下所示: $form.= '<option id="'.$result['temp_id'].'"value="'.$result['temp_html'].'">"'.$result['temp_name'].'"</option>
$form.= '<option id="'.$result['temp_id'].'"value="'.$result['temp_html'].'">"'.$result['temp_name'].'"</option>';
php代码:
<?php
function LoadTemplate(){
require('connect_db.php');
$sql = "SELECT temp_id, temp_name, temp_html FROM templates WHERE temp_id=temp_id";
$query = mysqli_query($con, $sql);
$form='<select id="template" name="template">';
$form.='<option value="">Select Template</option>';
while($result = mysqli_fetch_assoc($query)){
$form.= '<option id="'.$result['temp_id'].'"value="'.$result['temp_html'].'">"'.$result['temp_name'].'"</option>';
}
$form.='</select>';
return $form;
}
if(isset($_REQUEST['submit'])){
$to = $_POST['recipient'];
$subject = $_POST['subject'];
var_dump($message);
//$message = file_get_contents($_REQUEST['template'], "r") or exit("Unable to open file");
$headers = "Content-type: text/html\r\n";
$mail_send = mail($to, $subject, $message, $headers);
if($mail_send){
echo 'Mail Send ';
}else{
echo 'Try Later';
}
}
?>
我不明白你的问题,是什么错误?没有错误,我尝试的是提取存储在选项值中的HTML,将其保存在$message变量中,并在mail()中使用它发送电子邮件
<?php
function LoadTemplate(){
require('connect_db.php');
$sql = "SELECT temp_id, temp_name, temp_html FROM templates WHERE temp_id=temp_id";
$query = mysqli_query($con, $sql);
$form='<select id="template" name="template">';
$form.='<option value="">Select Template</option>';
while($result = mysqli_fetch_assoc($query)){
$form.= '<option id="'.$result['temp_id'].'"value="'.$result['temp_html'].'">"'.$result['temp_name'].'"</option>';
}
$form.='</select>';
return $form;
}
if(isset($_REQUEST['submit'])){
$to = $_POST['recipient'];
$subject = $_POST['subject'];
var_dump($message);
//$message = file_get_contents($_REQUEST['template'], "r") or exit("Unable to open file");
$headers = "Content-type: text/html\r\n";
$mail_send = mail($to, $subject, $message, $headers);
if($mail_send){
echo 'Mail Send ';
}else{
echo 'Try Later';
}
}
?>