Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么用PHP在电子邮件收发中打印html代码?_Php_Mysql - Fatal编程技术网

为什么用PHP在电子邮件收发中打印html代码?

为什么用PHP在电子邮件收发中打印html代码?,php,mysql,Php,Mysql,我正在为Phpmailer-crone作业编写代码。 电子邮件正在发送和接收,但我为什么在电子邮件中接收HTMLcode。而不是HTML模板 我还使用了适当的电子邮件标题,并对其他用户的电子邮件帐户进行了测试。但在电子邮件中打印HTML代码也有同样的问题 我还在消息中使用Hello而不是模板代码。但在电子邮件接收中打印Hello也有同样的问题 Php代码 //database connection require_once("include/config.inc.php");

我正在为
Php
mailer-crone作业编写代码。 电子邮件正在发送和接收,但我为什么在电子邮件中接收
HTML
code。而不是
HTML
模板

我还使用了适当的电子邮件标题,并对其他用户的电子邮件帐户进行了测试。但在电子邮件中打印
HTML
代码也有同样的问题

我还在消息中使用
Hello
而不是模板代码。但在电子邮件接收中打印
Hello
也有同样的问题

Php代码

 //database connection
        require_once("include/config.inc.php");
        require_once("include/functions.inc.php");

        //init function 
        mailerCrone();

        //defined functions
        function mailerCrone() {

            $site_admin  = 'myemail@gmail.com';
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
            $headers = "From: " . $site_admin . "\r\n";
            $headers .= "Reply-To: ". $site_admin . "\r\n";

            $currentdate =  date('Y-m-d H:i:s');

            //get data to send mails 
            $getDataTomail = mysql_query("SELECT * FROM sendmails where status = 0 ORDER BY id ASC limit 0,10");

            while($resDataTomail = mysql_fetch_array($getDataTomail)) {

                $templateId = $resDataTomail['templ_id'];   
                $dataPreparedId = $resDataTomail['id'];     

                //get the template data
                $getTemplate = mysql_query("SELECT * FROM templates where id  = $templateId");
                $resTemplate = mysql_fetch_array($getTemplate);
                echo $msg = '<html><body>'.$resTemplate['templ_content'].'</body></html>';
                //mail($to, $subject, $message, $headers);
                $mailResponce = mail($resDataTomail['subs_email'], $resTemplate['templ_name'], $msg, $headers);

                if($mailResponce == '1') { 
                    //update status of selected data after send mail
                    $updateSendMailData = mysql_query("UPDATE sendmails SET status = '1' WHERE id = $dataPreparedId") or die(mysql_error());

                }
            }
        }
//数据库连接
需要一次(“include/config.inc.php”);
需要一次(“include/functions.inc.php”);
//初始化函数
mailerCrone();
//定义函数
函数mailerCrone(){
$site\u admin=myemail@gmail.com';
$headers=“MIME版本:1.0”。\r\n”;
$headers.=“内容类型:text/html;字符集=iso-8859-1”。\r\n”;
$headers=“From:”.$site\u admin.\r\n”;
$headers.=“回复:”.$site\u admin.\r\n”;
$currentdate=日期('Y-m-d H:i:s');
//获取数据以发送邮件
$getDataTomail=mysql_查询(“从sendmails中选择*,其中状态=0按id排序ASC限制0,10”);
而($resDataTomail=mysql\u fetch\u数组($getDataTomail)){
$templateId=$resDataTomail['templateId'];
$dataPreparedId=$resDataTomail['id'];
//获取模板数据
$getTemplate=mysql_查询(“从id=$templateId的模板中选择*);
$resTemplate=mysql\u fetch\u数组($getTemplate);
echo$msg='.$resTemplate['temp_content'].';
//邮件($to、$subject、$message、$headers);
$mailResponse=mail($resDataTomail['subs_email'],$resTemplate['temp_name'],$msg,$headers);
如果($mailResponse=='1'){
//发送邮件后更新所选数据的状态
$updateSendMailData=mysql\u查询(“更新sendmails集状态='1',其中id=$dataPreparedId”)或死亡(mysql\u错误());
}
}
}
更改此项:
$headers=“From:”$网站管理员。“\r\n”

对此:

$headers.=“From:”$网站管理员。“\r\n”

我建议不要使用
mail()
函数,而是尝试使用,但有一个好方法可以确保将标题更改为:

$to = 'bob@example.com';
$subject = 'Website Change Reqest';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

通过

您是否尝试过将html标记周围的单引号
更改为双引号
。我有时发现,当使用单引号和
mail()
时,html并不总是正确解析-
echo$msg=“”。$resTemplate['temp_content']”;
是的,您错过了
(点)在第三行标题上的
=
之前;)