0
votes

A PHP Error was encountered Severity: 8192

Message: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated

Filename: libraries/Email.php

Line Number: 1868

Backtrace:

File: /home/abc/public_html/isol/application/controllers/Home.php Line: 261 Function: send

File: /home/abc/public_html/isol/index.php Line: 315 Function: require_once

When ever I send email I get this error . My code is below

$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('[email protected]');
$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
Php version, ci version? - Alex
php version is 7.2 CI 3.1.6 - Ammar Khan

2 Answers

0
votes

This problem was addressed in an update.

You can read more about it here: https://github.com/bcit-ci/CodeIgniter/issues/5300

So you should upgrade CI's /system to the newest version and your problems should go away.

You could also probably silence depreciated warnings in the switch statement on top of the index.php page but that's more of a bandaid rather than a fix.

0
votes

In 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'
);

In your controller

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

I created a template as a view in a new view folder 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>

Let me know if it's helpful.