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('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();
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.
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.
Related
I Tried to send email from codeigniter3 but it's showed my this error
The following SMTP error was encountered: 0 php_network_getaddresses: getaddrinfo failed: Name or service not known
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
I have a file on application/config/email.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
$config = array(
'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
'smtp_host' => 'smtp.example.com',
'smtp_port' => 465,
'smtp_user' => 'my email',
'smtp_pass' => 'pass',
'smtp_crypto' => 'ssl', //can be 'ssl' or 'tls' for example
'mailtype' => 'text', //plaintext 'text' mails or 'html'
'smtp_timeout' => '4', //in seconds
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
my controller is
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class EmailController extends CI_Controller {
public function __construct() {
parent:: __construct();
$this->load->helper('url');
}
public function index() {
$this->load->view('email/contact');
}
function send() {
$this->load->config('email');
$this->load->library('email');
$from = $this->config->item('smtp_user');
$to = $this->input->post('to');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
$this->email->set_newline("\r\n");
$this->email->from($from);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {
echo 'Your Email has successfully been sent.';
} else {
show_error($this->email->print_debugger());
}
}
}
my view is here
<!DOCTYPE html>
<html>
<head>
<title>CodeIgniter Send Email</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<h3>Use the form below to send email</h3>
<form method="post" action="<?=base_url('email')?>" enctype="multipart/form-data">
<input type="email" id="to" name="to" placeholder="Receiver Email">
<br><br>
<input type="text" id="subject" name="subject" placeholder="Subject">
<br><br>
<textarea rows="6" id="message" name="message" placeholder="Type your message here"></textarea>
<br><br>
<input type="submit" value="Send Email" />
</form>
</div>
</body>
</html>
I have written a function to send email with attachment.i used PHPMailer class.
Email is send,but the attachment is not getting.
My Controller Code
public function send_mail()
{
$this->load->library('email');
$subject = 'Request For Quotation';
$message = '<p>This message has been sent for testing purposes.</p>';
// Get full html:
$body =
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset='.strtolower(config_item('charset')).'" />
<title>'.html_escape($subject).'</title>
<style type="text/css">
body {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 16px;
}
</style>
</head>
<body>
'.$message.'
</body>
//</html>';
$this->load->library('M_pdf');
$this->m_pdf->pdf->setTitle('Request for Quotation');
$html = 'hiiiiiiiiiiiiiiiiiiiiiiiiiiiiii';
$this->m_pdf->pdf->WriteHTML($html);
$content=$this->m_pdf->pdf->Output('RFQ.pdf',"S");
$result = $this->email->from('mm#jiklink.com')->to('jk#gmail.com')->subject($subject)->message($body)->attach($content, '', 'base64', '')->send();
var_dump($result); // echo '<br />'; echo $this->email->print_debugger(); exit;
}
use this code..............
$pdfFilePath = "PDF/RFQ.pdf";
$html='hiiiiiiiiiiiiiii';
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
ob_clean();
$this->m_pdf->pdf->Output($pdfFilePath,'F');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'Email',
'smtp_pass' => 'Password',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->helper('path');
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('Email');
$this->email->to('email');
$this->email->subject('Subject');
$this->email->attach($pdfFilePath);
$this->email->send();
now i'm trying user images(user_pic,background_image) upoload.
but my codes not working.
should i be doing something different? Not really sure what's going wrong.
Here my html code
<form action="<?=base_url();?>edit/up_profile/" method="post" enctype="multipart/form-data">
<input type="file" name="pic_file">
<input type="file" name="pic_bgfile" />
<button type="submit">
my controller code is
if($this->form_validation->run() === false){
}else{
$config = array(
'upload_path' => "./images/u/photo",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload',$config);
if($this->upload->do_upload('pic_file')){
$data['profile_image'] = $this->upload->data();
}else if($this->upload->do_upload('pic_bgfile')){
$data['pic_bgfile'] = $this->upload->data();
}
$this->load->model('user_model');
$data = array(
'user_id' => $this->session->userdata('user_id'),
'info_tit' => $this->input->post('info_tit'),
'scope' => $this->input->post('scope')
);
$this->user_model->p_update($data);
//redirect
redirect('/edit/profile/', 'location', 301);
}
You should use CodeIgniter's own upload class instead of using html code.
In the view, or rather, the .html file:
<?php
echo form_open_multipart('user/upload_picture');
?>
<input type="file" name="userfile" />
<br /><br />
<input type="submit" value="submit" />
</form>
Noted that in 'user/upload_picture', 'user' is the name of the controller, 'upload_picture' is the method in 'user'.
In the 'upload_picture' method:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg';
$config['max_size'] = 0;
$config['max_width'] = 0;
$config['max_height'] = 0;
$config['file_name'] = 'Apink.jpg';
$this->load->library('upload', $config);
$this->upload->do_upload();
The View :
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?> <!-- Error Message will show up here -->
<?php echo form_open_multipart('upload_controller/do_upload');?>
<?php echo "<input type='file' name='userfile' size='20' />"; ?>
<?php echo "<input type='submit' name='submit' value='upload' /> ";?>
<?php echo "</form>"?>
</body>
</html>
The Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function file_view(){
$this->load->view('file_view', array('error' => ' ' ));
}
public function do_upload(){
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('file_view', $error);
}
}
}
?>
Note : You can change preferences depending upon the file you wish to upload.
The Page to show uploaded file:
<html>
<head>
<title>Upload File Specification</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?></p>
</body>
</html>
You can use clear function after first image upload
unset($config);
$this->image_lib->clear();
See CI Manual
https://codeigniter.com/user_guide/libraries/image_lib.html
I am working on a project where volunteers have to fill in registration form.
I want volunteers to be able to upload a profile image and save image name to database as well as the post data on the same form.
How can I achieve that?
In the success part of upload form could do a if statement like below for update
Update
$user_info = $this->get_user();
if ($user_info) {
$image_info = $this->upload->data();
$data = array(
'username' => $user_info['username'],
'image' => $image_info['file_name']
);
// Only updates password if post value true
if(isset($_POST['password'])) {
$data = array(
'password' => $this->input->post('password');
);
}
$this->db->where('id', $user_info['id']);
$this->db->update('tablename', $data);
}
Else In the success part of upload form could do insert like below
Insert
$image_info = $this->upload->data();
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
'image' => $image_info['file_name']
);
$this->db->insert('tablename', $data);
Upload Controller
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0'; // Unlimited
$config['max_width'] = '0'; // Unlimited
$config['max_height'] = '0'; // Unlimited
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
$input_name = "userfile";
if ( ! $this->upload->do_upload($input_name))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$user_info = $this->get_user();
if ($user_info) {
$image_info = $this->upload_data();
$data = array(
'username' => $user_info['username'],
'image' => $image_info['file_name']
);
$this->db->where('id', $user_info['id']);
$this->db->update('tablename', $data);
}
$this->load->view('upload_success', $data);
}
}
public function get_user() {
// your user model data
}
}
?>
View
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="text" name="name"/>
<input type="password" name="password"/>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
Upload library
Codeigniter 2 http://www.codeigniter.com/userguide2/libraries/file_uploading.html
Codeigniter 3 http://www.codeigniter.com/user_guide/libraries/file_uploading.html
your question is not clear ,
provide ,view ,controller as well.
anyways see this post it will help you.
click here
or
use <?php echo form_open_multipart('yourcontroler/add');?>
in your view file when dealing with image and text data.
in controller ,the best practice is to define two function one for image upload the other to validate ,and filter data.Like
public function do_upload() {
$path = '_assets/images/';
$fileName = 'userpic.png';
$config = array(
'allowed_types' => 'jpg|png|gif',
'upload_path' => $path,
'max_size' => '200',
'overwrite' => true,
'file_name' => $fileName,
'max_height' => "300",
'max_width' => "300",
);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('logo')) {
echo "error ";
die;
} else {
$imageData = $this->upload->data();
}
}
and for data storing use simple function you usually do with form input.
I cant seem to get CI2's captcha helper to work... Can someone point out what I am doing wrong?
I think I've followed all the steps on the doc's but Im not getting anything event a print_r(get_defined_vars()) isnt showing anything... :(
My Controller
function index()
{
$this->load->helper('form');
$this->load->helper('captcha');
$this->load->model('captcha');
$vals = array(
'word' => 'Random word',
'img_path' => '../images/captcha/',
'img_url' => 'http://mysite/images/captcha/',
'font' => '../../system/fonts/texb.ttf',
'img_width' => '150',
'img_height' => 30,
'expiration' => 7200,
"time" => time()
);
$data['cap'] = create_captcha($vals);
$cap = array(
'captcha_time' => $vals['time'],
'ip_address' => $this->input->ip_address(),
'word' => $vals['word']
);
$this->captcha_model->insert_captcha($cap);
//print_r(get_defined_vars());
$data['main_content'] = 'admin/landing.php';
$this->load->view('includes/template', $data);
}
My Model
function input_captcha($data)
{
$query = $this->db->insert_string('captcha', $data);
$this->db->query($query);
}
My View
<section>
<h3>You must captcha this captcha before proceeding to your demise!</h3>
<article>
<?php echo form_open('admin/auth');?>
<p>Who the F are you?</p>
<?php echo form_input('email', 'your real email!');?>
<br>
<?php echo 'Submit the word you see below:';?>
<br>
<?php echo $cap['image'];?>
<br>
<?php echo '<input type="text" name="captcha" value="" />'; ?>
<br>
<?php echo form_submit('submit', 'Send It!');?>
<?php echo form_close();?>
</article>
</section>
The problem was in the path's for images. One thing, even with the log threshold set to four, I was getting NO indication of any kind of problem. I set it to absolute paths and everything worked fine...
function index()
{
$this->load->helper('form');
$this->load->helper('captcha');
$this->load->model('captcha_model');
$vals = array(
'img_path' => '/var/www/mysite.com/images/captcha/',
'img_url' => 'http://mysite.com/images/captcha/',
'font' => '../../system/fonts/texb.ttf',
'img_width' => '150',
'img_height' => 30,
'expiration' => 7200,
"time" => time()
);
$data['cap'] = create_captcha($vals);
$cap = array(
'captcha_time' => $data['cap']['time'],
'ip_address' => $this->input->ip_address(),
'word' => $data['cap']['word']
);
$this->captcha_model->add_captcha($cap);
$data['main_content'] = 'admin/landing.php';
$this->load->view('includes/template', $data);
}