使用代码点火器发送电子邮件

时间:2018-08-09 13:59:49

标签: codeigniter email

遇到PHP错误 严重程度:8192

消息:idn_to_ascii():不推荐使用INTL_IDNA_VARIANT_2003

文件名:libraries / Email.php

行号:1868

回溯:

文件:/home/abc/public_html/isol/application/controllers/Home.php 线:261 功能:发送

文件:/home/abc/public_html/isol/index.php 线:315 功能:require_once

每当我发送电子邮件时,都会出现此错误。 我的代码在

$config = Array('mailtype' => 'html');
$this->load->library('email',$config);
$this->email->set_newline("\r\n"); 
$this->email->from(from_email,site_title); 
$this->email->to('ammarkhan94x@gmail.com');
$this->email->subject(site_title.' - Account Registration'); 
$this->email->message('<p><b>Dear '.$fname.' '.$lname.',</b></p>'.
'<p>Thank You for registration on '.site_title.', Your account is created successfully please login & update your account details.</p>');		
$result = $this->email->send();

2 个答案:

答案 0 :(得分:0)

在Application / config / email.php中

<?php

$config['email_conf'] = Array(
    'protocol' => 'smtp',
    'smtp_host' => '-your smtp port-',
    'smtp_port' => -your smtp port-,
    'smtp_user' => '-your email--',
    'smtp_pass' => '-your smtp pass',
    'mailtype' => 'html',
    'charset' => 'iso-8859-1'
);

在您的控制器中

     private function sendMail($mailBody) {
        //en-tête de mail
        $filename = 'assets/images/logo.png';
        //loader les fichiers de configuration
        $this->config->load('email');
        $conf = $this->config->item('email_conf');
        $this->load->library('email', $conf);
        $this->email->set_newline("\r\n");
        $this->load->library('email');

        $this->email->from('mail address', 'your name');
        $this->email->subject('Support Application');
        $this->email->attach($filename);
        $this->email->to('email dest');

        $cid = $this->email->attachment_cid($filename);

        $message = '<div><img src="cid:' . $cid . '" alt="photo1"/></div>';
        $message .=  $mailBody  ;

        //array à passer au template email
        $data = array(
            'userName' =>  $this->session->userdata('username'),
            'email' => $this->session->userdata ('email'),
            'message' => $message
        );
        $body = $this->load->view('email/template.php', $data, TRUE);
        $this->email->message($body);
        $this->email->set_crlf( "\r\n" );
        $result = $this->email->send();
    }
}

我在新视图文件夹views / email / template.php中创建了一个模板作为视图

<html lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Template contact / XXX</title>
    </head>
    <body>
        <p>
            <FONT face="Verdana" size = "4" ><?php echo $message; ?></FONT>
            <FONT face="Verdana" size = "4" >Message envoyé par : <?php echo   $userName; ?></FONT>
            <FONT face="Verdana" size = "4" >test mail : <?php echo $email; ?></FONT>
        </p> 
    </body>
</html>

让我知道是否有帮助。

答案 1 :(得分:0)

此问题已在更新中解决。

您可以在此处了解更多信息:https://github.com/bcit-ci/CodeIgniter/issues/5300

因此,您应该将CI的/system升级到最新版本,然后您的问题就会消失。

您可能还可以在index.php页面顶部的switch语句中使已贬值的警告保持静音,但这更多是创可贴而不是解决方法。