Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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_Html_Email_Opencart - Fatal编程技术网

如何使用PHP在电子邮件中使用HTML标记?

如何使用PHP在电子邮件中使用HTML标记?,php,html,email,opencart,Php,Html,Email,Opencart,我刚刚回答了最后一个问题,但现在我又被卡住了。。我正在使用OpenCart,我想更改您在我的OpenCart网站商店注册时收到的电子邮件的样式。但当我使用add this(添加此)时,它只是在电子邮件中显示为普通文本: $message .= '<img src="logo.png" />' "\n"; 我将它粘贴在代码中的一些地方,但它从未起作用,它仍然在电子邮件中以文本形式显示HTML标记 我将在这里粘贴我的代码(来自OpenCart),有人能告诉我在哪里粘贴代码,或者通过PH

我刚刚回答了最后一个问题,但现在我又被卡住了。。我正在使用OpenCart,我想更改您在我的OpenCart网站商店注册时收到的电子邮件的样式。但当我使用add this(添加此)时,它只是在电子邮件中显示为普通文本:

$message .= '<img src="logo.png" />' "\n";
我将它粘贴在代码中的一些地方,但它从未起作用,它仍然在电子邮件中以文本形式显示HTML标记

我将在这里粘贴我的代码(来自OpenCart),有人能告诉我在哪里粘贴代码,或者通过PHP在电子邮件中使用HTML的另一种方式吗

<?php
class ModelAccountCustomer extends Model {
    public function addCustomer($data) {
        if (isset($data['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($data['customer_group_id'], $this->config->get('config_customer_group_display'))) {
            $customer_group_id = $data['customer_group_id'];
        } else {
            $customer_group_id = $this->config->get('config_customer_group_id');
        }

        $this->load->model('account/customer_group');

        $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);

        $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET store_id = '" . (int)$this->config->get('config_store_id') . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', customer_group_id = '" . (int)$customer_group_id . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', status = '1', approved = '" . (int)!$customer_group_info['approval'] . "', date_added = NOW()");

        $customer_id = $this->db->getLastId();

        $this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', company = '" . $this->db->escape($data['company']) . "', company_id = '" . $this->db->escape($data['company_id']) . "', tax_id = '" . $this->db->escape($data['tax_id']) . "', address_1 = '" . $this->db->escape($data['address_1']) . "', address_2 = '" . $this->db->escape($data['address_2']) . "', city = '" . $this->db->escape($data['city']) . "', postcode = '" . $this->db->escape($data['postcode']) . "', country_id = '" . (int)$data['country_id'] . "', zone_id = '" . (int)$data['zone_id'] . "'");

        $address_id = $this->db->getLastId();

        $this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");

        $this->language->load('mail/customer');

$mail=newmail();
$mail->protocol=$this->config->get('config\u mail\u protocol');
$mail->parameter=$this->config->get('config\u mail\u parameter');
$mail->hostname=$this->config->get('config_smtp_host');
$mail->username=$this->config->get('config_smtp_username');
$mail->password=$this->config->get('config_smtp_password');
$mail->port=$this->config->get('config_smtp_port');
$mail->timeout=$this->config->get('config\u smtp\u timeout');
$mail->setTo($data['email']);
$mail->setFrom($this->config->get('config_email');
$mail->setSender($this->config->get('config_name');
$mail->setSubject(html_entity_decode($subject,ENT_引号,'UTF-8'));
$mail->setText(html_实体_解码($message,ENT_引号,'UTF-8');
$mail->send();
//如果启用了新帐户电子邮件,则发送至主管理员电子邮件
如果($this->config->get('config\u account\u mail')){
$message=$this->language->get('text\u signup')。“\n\n”;
$message.=$this->language->get('text\u website')。$this->config->get('config\u name')。“\n”;
$message.=$this->language->get('text_firstname')。$data['firstname']。“\n”;
$message.=$this->language->get('text_lastname')。$data['lastname']。“\n”;
$message.=$this->language->get('text\u customer\u group')。$customer\u group\u info['name']。“\n”;
如果($data[“公司]){
$message.=$this->language->get('text_company').'.$data['company'.]。“\n”;
}
$message.=$this->language->get('text_email')。$data['email']。“\n”;
$message.=$this->language->get('text_telephone')。$data['telephone']。“\n”;
$mail->setTo($this->config->get('config_email');
$mail->setSubject(html\u entity\u decode($this->language->get('text\u new\u customer')、ENT\u QUOTES、'UTF-8');
$mail->setText(html_实体_解码($message,ENT_引号,'UTF-8');
$mail->send();
//如果启用了新帐户电子邮件,则发送其他警报电子邮件
$emails=explode(“,”,$this->config->get('config\u alert\u emails');
foreach($email作为$email){
如果(strlen($email)>0和&preg_匹配('/^[^\@]+.*.\.[a-z]{2,6}$/i',$email)){
$mail->setTo($email);
$mail->send();
}
}
}
}
公共函数editCustomer($data){
$this->db->query(“UPDATE”.db_PREFIX.”客户集名字=“$this->db->escape($data['firstname'])。”,lastname=“$this->db->escape($data['lastname'])。”,email=“$this->db->escape($data['email'])。”,电话=“$this->db->escape($data['phone'])。”,传真=““$this->db->escape($data['fax'])。“'WHERE customer_id='”(int)$this->customer->getId();
}
公共函数editPassword($email,$password){
$this->db->query(“UPDATE”.db_PREFIX.”customer SET salt='“$this->db->escape($this->salt=substr(md5(uniqid(rand(),true)),0,9))。”,password='“$this->db->escape(sha1($salt.sha1($salt.sha1($password))))。“'WHERE LOWER(email)='””。“$this->->->db->escape(utf8\u strtower($email))”);
}
公共活动编辑通讯($通讯){
$this->db->query(“更新”.db_前缀.”客户集新闻稿='”(int)$newsletter.“'WHERE customer_id='”(int)$this->customer->getId();
}
公共函数getCustomer($customer\u id){
$query=$this->db->query(“SELECT*FROM”.db\u PREFIX.“customer WHERE customer\u id='”(int)$customer\u id.“”;
返回$query->row;
}
公共函数getCustomerByMail($email){
$query=$this->db->query(“选择“.db_前缀中的*”。客户所在位置较低(电子邮件)='”“$this->db->escape(utf8_strtolower($email))。””);
返回$query->row;
}
公共函数getCustomerByToken($token){
$query=$this->db->query(“选择“.db_PREFIX.”中的“.customer WHERE token=””。“$this->db->escape($token)。”和token!=”);
$this->db->query(“更新”.db_前缀。“客户设置令牌=”);
返回$query->row;
}
公共函数getCustomers($data=array()){
$sql=“SELECT*,CONCAT(c.firstname,,,c.lastname)作为名称,cg.name作为来自“.DB\u PREFIX.”的客户组左加入“.DB\u PREFIX.”客户组cg ON(c.customer\u group\u id=cg.customer\u group\u id)”;
$introde=array();
if(isset($data['filter\u name'])和&!is\u null($data['filter\u name'])){
$implode[]=“LCASE(CONCAT(c.firstname,,,c.lastname))类似'。$this->db->escape(utf8\u strtolower($data['filter\u name']))。“%”;
}
如果(isset($data['filter\u email'])和(&!is\u null($data['filter\u email'])){
$introde[]=“LCASE(c.email)='””$this->db->escape(utf8\u strtolower($data['filter\u email'])))。“”;
}
if(设置($data['filter\u customer\u group\u id'])和&!为空($data['filter\u customer\u group\u id'])){
$implode[]=“cg.customer\u group\u id=”。“$this->db->escape($data['filter\u customer\u group\u id'))。”;
}   
if(isset($data['filter\u status'])和&!is\u null($data['filter\u status'])){
$introde[]=“c.status
<?php
class ModelAccountCustomer extends Model {
    public function addCustomer($data) {
        if (isset($data['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($data['customer_group_id'], $this->config->get('config_customer_group_display'))) {
            $customer_group_id = $data['customer_group_id'];
        } else {
            $customer_group_id = $this->config->get('config_customer_group_id');
        }

        $this->load->model('account/customer_group');

        $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);

        $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET store_id = '" . (int)$this->config->get('config_store_id') . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', customer_group_id = '" . (int)$customer_group_id . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', status = '1', approved = '" . (int)!$customer_group_info['approval'] . "', date_added = NOW()");

        $customer_id = $this->db->getLastId();

        $this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', company = '" . $this->db->escape($data['company']) . "', company_id = '" . $this->db->escape($data['company_id']) . "', tax_id = '" . $this->db->escape($data['tax_id']) . "', address_1 = '" . $this->db->escape($data['address_1']) . "', address_2 = '" . $this->db->escape($data['address_2']) . "', city = '" . $this->db->escape($data['city']) . "', postcode = '" . $this->db->escape($data['postcode']) . "', country_id = '" . (int)$data['country_id'] . "', zone_id = '" . (int)$data['zone_id'] . "'");

        $address_id = $this->db->getLastId();

        $this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");

        $this->language->load('mail/customer');
        **$subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));

        $message = sprintf($this->language->get('text_welcome'), $this->config->get('config_name')) . "\n\n";

        if (!$customer_group_info['approval']) {
            $message .= $this->language->get('text_login') . "\n";
        } else {
            $message .= $this->language->get('text_approval') . "\n";
        }

        $message .= $this->url->link('account/login', '', 'SSL') . "\n\n";
        $message .= $this->language->get('text_services') . "\n\n";
        $message .= $this->language->get('text_thanks') . "\n";
        $message .= $this->config->get('config_name');**
        $mail = new Mail();
        $mail->protocol = $this->config->get('config_mail_protocol');
        $mail->parameter = $this->config->get('config_mail_parameter');
        $mail->hostname = $this->config->get('config_smtp_host');
        $mail->username = $this->config->get('config_smtp_username');
        $mail->password = $this->config->get('config_smtp_password');
        $mail->port = $this->config->get('config_smtp_port');
        $mail->timeout = $this->config->get('config_smtp_timeout');             
        $mail->setTo($data['email']);
        $mail->setFrom($this->config->get('config_email'));
        $mail->setSender($this->config->get('config_name'));
        $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
        $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
        $mail->send();

        // Send to main admin email if new account email is enabled
        if ($this->config->get('config_account_mail')) {
            $message  = $this->language->get('text_signup') . "\n\n";
            $message .= $this->language->get('text_website') . ' ' . $this->config->get('config_name') . "\n";
            $message .= $this->language->get('text_firstname') . ' ' . $data['firstname'] . "\n";
            $message .= $this->language->get('text_lastname') . ' ' . $data['lastname'] . "\n";
            $message .= $this->language->get('text_customer_group') . ' ' . $customer_group_info['name'] . "\n";

            if ($data['company']) {
                $message .= $this->language->get('text_company') . ' '  . $data['company'] . "\n";
            }

            $message .= $this->language->get('text_email') . ' '  .  $data['email'] . "\n";
            $message .= $this->language->get('text_telephone') . ' ' . $data['telephone'] . "\n";

            $mail->setTo($this->config->get('config_email'));
            $mail->setSubject(html_entity_decode($this->language->get('text_new_customer'), ENT_QUOTES, 'UTF-8'));
            $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
            $mail->send();

            // Send to additional alert emails if new account email is enabled
            $emails = explode(',', $this->config->get('config_alert_emails'));

            foreach ($emails as $email) {
                if (strlen($email) > 0 && preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $email)) {
                    $mail->setTo($email);
                    $mail->send();
                }
            }
        }
    }

    public function editCustomer($data) {
        $this->db->query("UPDATE " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
    }

    public function editPassword($email, $password) {
        $this->db->query("UPDATE " . DB_PREFIX . "customer SET salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "' WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");
    }

    public function editNewsletter($newsletter) {
        $this->db->query("UPDATE " . DB_PREFIX . "customer SET newsletter = '" . (int)$newsletter . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
    }

    public function getCustomer($customer_id) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");

        return $query->row;
    }

    public function getCustomerByEmail($email) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");

        return $query->row;
    }

    public function getCustomerByToken($token) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE token = '" . $this->db->escape($token) . "' AND token != ''");

        $this->db->query("UPDATE " . DB_PREFIX . "customer SET token = ''");

        return $query->row;
    }

    public function getCustomers($data = array()) {
        $sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cg.name AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group cg ON (c.customer_group_id = cg.customer_group_id) ";

        $implode = array();

        if (isset($data['filter_name']) && !is_null($data['filter_name'])) {
            $implode[] = "LCASE(CONCAT(c.firstname, ' ', c.lastname)) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
        }

        if (isset($data['filter_email']) && !is_null($data['filter_email'])) {
            $implode[] = "LCASE(c.email) = '" . $this->db->escape(utf8_strtolower($data['filter_email'])) . "'";
        }

        if (isset($data['filter_customer_group_id']) && !is_null($data['filter_customer_group_id'])) {
            $implode[] = "cg.customer_group_id = '" . $this->db->escape($data['filter_customer_group_id']) . "'";
        }   

        if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
            $implode[] = "c.status = '" . (int)$data['filter_status'] . "'";
        }   

        if (isset($data['filter_approved']) && !is_null($data['filter_approved'])) {
            $implode[] = "c.approved = '" . (int)$data['filter_approved'] . "'";
        }   

        if (isset($data['filter_ip']) && !is_null($data['filter_ip'])) {
            $implode[] = "c.customer_id IN (SELECT customer_id FROM " . DB_PREFIX . "customer_ip WHERE ip = '" . $this->db->escape($data['filter_ip']) . "')";
        }   

        if (isset($data['filter_date_added']) && !is_null($data['filter_date_added'])) {
            $implode[] = "DATE(c.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
        }

        if ($implode) {
            $sql .= " WHERE " . implode(" AND ", $implode);
        }

        $sort_data = array(
            'name',
            'c.email',
            'customer_group',
            'c.status',
            'c.ip',
            'c.date_added'
        );  

        if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
            $sql .= " ORDER BY " . $data['sort'];   
        } else {
            $sql .= " ORDER BY name";   
        }

        if (isset($data['order']) && ($data['order'] == 'DESC')) {
            $sql .= " DESC";
        } else {
            $sql .= " ASC";
        }

        if (isset($data['start']) || isset($data['limit'])) {
            if ($data['start'] < 0) {
                $data['start'] = 0;
            }           

            if ($data['limit'] < 1) {
                $data['limit'] = 20;
            }   

            $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
        }       

        $query = $this->db->query($sql);

        return $query->rows;    
    }

    public function getTotalCustomersByEmail($email) {
        $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");

        return $query->row['total'];
    }

    public function getIps($customer_id) {
        $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_ip` WHERE customer_id = '" . (int)$customer_id . "'");

        return $query->rows;
    }   

    public function isBanIp($ip) {
        $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_ban_ip` WHERE ip = '" . $this->db->escape($ip) . "'");

        return $query->num_rows;
    }   
}
?>
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
$mail->setHTML($message);