【问题标题】:Sending email using code igniter使用 codeigniter 发送电子邮件
【发布时间】:2018-08-09 13:59:49
【问题描述】:

遇到 PHP 错误 严重性:8192

消息:idn_to_ascii():INTL_IDNA_VARIANT_2003 已弃用

文件名:libraries/Email.php

行号:1868

回溯:

文件:/home/abc/public_html/iso/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();

【问题讨论】:

  • php版,ci版?
  • php 版本为 7.2 CI 3.1.6

标签: codeigniter email


【解决方案1】:

此问题已在更新中得到解决。

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

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

您还可以在index.php 页面顶部的 switch 语句中消除折旧警告,但这更像是一种创可贴,而不是修复。

【讨论】:

    【解决方案2】:

    在 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>
    

    如果有帮助,请告诉我。

    【讨论】:

    • 没用
    • 会是服务器问题吗?
    猜你喜欢
    • 2017-12-07
    • 2013-01-07
    • 2019-08-07
    • 1970-01-01
    • 2015-11-10
    • 2018-03-18
    • 1970-01-01
    相关资源
    最近更新 更多