0

我正在为Phpmailer cron 工作编写代码。电子邮件正在发送和接收,但为什么我HTML在电子邮件中收到代码。而不是HTML模板。

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

我也在<html><body><h2>Hello</h2></body></html>消息中使用而不是模板代码。<html><body><h2>Hello</h2></body></html>但在电子邮件接收中打印同样的问题。

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());

                }
            }
        }
4

2 回答 2

2

改变这个:
$headers = "From: " 。$site_admin 。"\r\n";

为此:
$headers .= "From:" 。$site_admin 。"\r\n";

于 2013-01-21T06:48:55.543 回答
0

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

$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";

通过CSS 技巧

于 2013-01-21T06:52:15.657 回答