简体   繁体   中英

why printing html code in email receive send by PHP?

i am writing a code for Php mailer crone job. email is going and receiving but why i am receiving HTML code in email. instead of HTML template.

i also used proper email header and also test on other users email accounts. but same problem printing HTML code in email.

i also use <html><body><h2>Hello</h2></body></html> in message instead of template code. but same problem printing <html><body><h2>Hello</h2></body></html> in email receive.

Php code

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

                }
            }
        }

Change this:
$headers = "From: " . $site_admin . "\\r\\n";

To this:
$headers .= "From: " . $site_admin . "\\r\\n";

I recommend to not use mail() function, instead try with phpMailer , but One good way to be sure is to change your headers to this:

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

via CSS-Tricks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM