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();
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>
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.
I'm using Yii 2.0 advanced template, and in the back-end want to have something like this:
A menu of the left that should contains items, and when clicking on those items the corresponding pages to be open on the right. The menu of the left should be static and to not lose focus when items are clicked.
This means that I will probably need to use partial views? Is there some extension/widget that is doing what I need? I'm new in Yii so I'm really not sure how to solve this. Any suggestion or idea will be appreciated. I'm sure I'm not the only one that need this in Yii, but could not find something on google.
I think the simplest way is use layout. You can define a layout with the menu on the the left and the main page in rest of the page.
this could be a layout sample eg: 'mylayout.php'
<?php
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
/* #var $this \yii\web\View */
/* #var $content string */
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="<?php echo Yii::$app->request->baseUrl; ?>/dfenx.ico" type="image/x-icon" />
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => $this->title = Yii::$app->name ,
'brandUrl' => Yii::$app->homeUrl,
'brandOptions' =>[
'style' => 'font-family: palatino; font-size:24px;'
],
'options' => [
//'class' => 'navbar-inverse navbar-fixed-top',
'class' => 'navbar-default navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/user/register']];
$menuItems[] = ['label' => 'Login', 'url' => ['/user/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/user/logout'],
'linkOptions' => ['data-method' => 'post']
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<div class='col-lg-3 col-md-3' >
<!-- here your left menu -->
</div>
<div class='col-lg-9 col-md-9' >
<!-- here your content page-->
<?= $content ?>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">© Digital FenX <?= date('Y') ?></p>
<p class="pull-right"><?php // Yii::powered() ?></p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
in the controller you can set the layout you want use in this way
public function actionYourAction()
{
$this->layout = 'mylayout';
return $this->render(ourView', [
'model' =>$model,
'dataProvider' => $provider,
]);
}
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'm new to CodeIgniter PHP programmer, and am facing a problem of setting css, divs achieve include the templates created in the views folder as header, content and footer, css settings functioned normally, but there is a resource that is in CodeIgniter get the template to be in the views folder and you deploy the css settings, and this feature did not work. I'll put the lines of code to give you an idea.
file /controllers/home
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index(){
$this->load->view('html_header');
$this->load->view('cabecalho');
$this->load->view('menu_categorias');
$this->load->view('conteudo');
$this->load->view('rodape');
$this->load->view('html_footer');
}
}
file html_header.php
<?php echo doctype('xhtml1-trans'); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Meu website de receitas</title>
<?php
$meta = array(
array('name' => 'robots', 'content' => 'no-cache'),
array('name' => 'description', 'content' => 'Meu website de receitas'),
array('name' => 'keywords', 'content' => 'Receitas, doces, salgados, sobremesas, massas'),
array('name' => 'robots', 'content' => 'no-cache'),
array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')
);
echo meta($meta);
echo link_tag('assets/imgs/fork.ico', 'shortcut icon', 'image/ico');
echo link_tag('assets/css/teste.css');
?>
</head>
<body>
file cabeçalho.php
<div id="tres"></div>
file conteúdo.php
<div id="dois"></div>
file html_footer.php
<div id="quatro"></div>
</body>
</html>
file teste.css
#tres{
width: 200px;
left: 200px;
float: right;
border: solid 5px #000;
}
#dois{
width: 200px;
left: 200px;
float: right;
border: solid 5px #003399;
}
#cabecalho{
width: 200px;
left: 200px;
float: right;
border: solid 5px #333;
}
what not working in css and settings that were placed to # header.
I would like to know how to put to work.
Try to use this sintax:
$linkCss = array(
'href' => 'assets/css/teste.css',
'rel' => 'stylesheet',
'type' => 'text/css',
'media' => 'screen'
);
echo link_tag($linkCss );
And did you load HTML helper?
$this->load->helper('html');