Code is working but can't send many files.... only images can be sended controller
public function sende(){
$from = $_POST['from'];
$address = $_POST['address'];
$to_name = $_POST['to_name'];
$to_email = $_POST['to_email'];
$cc = $_POST['cc'];
$subject = $_POST['subject'];
$mesg = $_POST['mesg'];
$start = $_POST['start'];
$end = $_POST['end'];
$mid1 = $_POST['mid1'];
$mid2 = $_POST['mid2'];
$message = $start.$mid1.$mesg.$mid2.$end;
$config = array(
'useragent' => 'CodeIgniter',
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => '***',
'smtp_pass' => '**',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => '\r\n'
);
$this->load->library('email',$config);
$this->email->set_newline('\r\n');
$this->email->from($address,$from);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
$this->email->cc($cc);
$path = $this->config->item('server_root');
$file = $path.'/mshaadi/';
$this->load->library('upload');
$m = count($_FILES['atta']['name']);
$files = $_FILES;
for($i=0; $i< $m; $i++){
$_FILES['atta']['name']= $files['atta']['name'][$i];
$_FILES['atta']['type']= $files['atta']['type'][$i];
$_FILES['atta']['tmp_name']= $files['atta']['tmp_name'][$i];
$_FILES['atta']['error']= $files['atta']['error'][$i];
$_FILES['atta']['size']= $files['atta']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload('atta');
$a = $files['atta']['name'][$i];
$mm = base_url().'images/'.$a;
$this->email->attach($mm);
}
if($this->email->send()){
redirect('Email');
}else{
show_error($this->email->print_debugger());
}
}
private function set_upload_options(){
$config = array();
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png|pdf|sql|docx|pptx';
$config['max_size'] = '10000';
$config['overwrite'] = TRUE;
return $config;
}
Error while sending multiple attachment of docx, pptx
220-gator3150.hostgator.com ESMTP Exim 4.85 #2 Thu, 19 Nov 2015 00:10:43 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
220-gator3150.hostgator.com ESMTP Exim 4.85 #2 Thu, 19 Nov 2015 00:10:43 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
hello: 250-gator3150.hostgator.com Hello 127.0.0.1 [112.196.141.163]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250 HELP
from: 250 OK
to: 501 <>: missing or malformed local part
The following SMTP error was encountered: 501 <>: missing or malformed local part
data: 503-All RCPT commands were rejected with this error:
503-501 <>: missing or malformed local part
503 Valid RCPT command must precede DATA
The following SMTP error was encountered: 503-All RCPT commands were rejected with this error: 503-501 <>: missing or malformed local part 503 Valid RCPT command must precede DATA
500 unrecognized command
The following SMTP error was encountered: 500 unrecognized command
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Thu, 19 Nov 2015 07:10:37 +0100
From: "" <>
Return-Path: <>
Subject: =?ISO-8859-1?Q??=
Reply-To: "" <>
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <564d67dddeddc>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_564d67dddeddc"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_564d67dddeddc
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
--B_ALT_564d67dddeddc
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
--B_ALT_564d67dddeddc--
$this->load->library('email');
$this->load->helper('path');
$this->load->helper('directory');
//setting path to attach files
$path = set_realpath('assets/your_folder/');
$file_names = directory_map($path);
$this->email->clear(TRUE);
$this->email->to($address);
$this->email->from('your#example.com');
$this->email->subject('Here is your info '.$name);
$this->email->message('Hi Here is the info you requested.');
foreach($file_names as $file_name)
{
$this->email->attach($file_name);
}
$this->email->send();
For multiple attachments you can use the same function multiple times,On your code you haven't used multiple times and not given loop too.
Try using the full path instead of just the url-
$this->email->attach('C:\Users\xyz\Desktop\images\abc.png');
or
$attched_file= $_SERVER["DOCUMENT_ROOT"]."/uploads/".$file_name;
$this->email->attach($attched_file);
also try changing the charset as-
$config['charset'] = 'iso-8859-1';
Codeigniter send email with attach file
https://ellislab.com/codeigniter/user-guide/libraries/email.html
Related
i have use CodeIgniter 2.2.6
i am trying to sent email but i can't get error and not received email
<?php
class email_otp_demo extends CI_Controller
{
public function index()
{
$this->load->library('email');
$config = Array(
'protocol' => 'smpt',
'mailpath' => '/usr/sbin/sendmail,
//'mailpath' => 'www.google.com', also try
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587,
//'smtp_port' => 456, also try
'smtp_user' => 'my.email#gmail.com',
'smtp_pass' => 'mypassword',
'smtp_timeout'=>50,
'mailtype' => 'text',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'newline' =>'\r\n'
);
// glnlwboynexfjqxj
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$this->email->from('my.email#gmail.com', 'Social media website');
$this->email->to('sender#yahoo.com');
//$this->email->to('sender#gmail.com'); also try this
// $this->email->cc('another#another-example.com');
// $this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
echo $this->email->send();
echo "<hr>";
echo $this->email->print_debugger();
}
}
?>
i have get following output but not received email
1
Your message has been successfully sent using the following protocol: mail
User-Agent: CodeIgniter
Date: Sun, 4 Dec 2022 16:53:27 +0530
From: "Social media website" <renish.batada#gmail.com>
Return-Path: <renish.batada#gmail.com>
Reply-To: "renish.batada#gmail.com" <renish.batada#gmail.com>
X-Sender: renish.batada#gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <638c832f6b8c0#gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
=?iso-8859-1?Q?Email_Test?=
Testing the email class.
i have also try to enable and disable to step verification
but not received email
i use app password and original password but not workworking
I am working on sending email. I am on windows 7.
Here is my controller:
public function ilet(){
$name = $this->input->post("name");
$email = $this->input->post("email");
$message = $this->input->post("message");
$config = array(
"protocol" => "smtp",
"smtp_host" => "mail.pratikesnaf.com",
"smtp_port" =>"587",
"smtp_user" =>"deste#pratikesnaf.com",
"smtp_password" =>"********",
"starttls" =>true,
"charset" =>"utf-8",
"mailtype" =>"html",
"wordwrap" => true,
"newline" =>"\r\n",
);
$this->load->library("email", $config);
$this->email->from("mail.pratikesnaf.com");
$this->email->to("mail.pratikesnaf.com");
$this->email->subject("Müşteri bilgi mesajı");
$this->email->message("Kişinin Adı - " . $name .
" - Kişinin Email Adresi - " . $email . " - Kişinin Mesajı - " . $message);
$send = $this->email->send();
if($send)
{
echo "Mail gönderme işlemi başarılı";
}
else {
echo "Başarısız";
echo $this->email->print_debugger();
}
}
after that i fulfill the inputs and i submit the button. it says an error like this:
Başarısız220 server.tescilmerkezi.net ESMTP Exim 4.76 Tue, 10 Jul 2018 18:00:47 +0300
hello: 250-server.tescilmerkezi.net Hello www.pratikesnaf.com [185.85.237.26]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
Can you please help me how can i fix this error?
try to change these lines:
$this->email->from("mail.pratikesnaf.com");
$this->email->to("mail.pratikesnaf.com");
to
$this->email->from("yoursenderemail#pratikesnaf.com");
$this->email->to("receiveremail#blabla.com");
I've a registration form and and want to send email to "To Email" and at the same time want to insert user record in db , insertion is successfull but email is not sending using codeigniter here is my code snippet from model and controller resp.
model:
public function add_user()
{
$data=array(
'username'=>$this->input->post('user_name'),
'first_name' => $this->input->post('fname'),
'last_name' => $this->input->post('lname'),
'email'=>$this->input->post('email_address'),
'password'=>md5($this->input->post('password'))
);
return $this->db->insert('user',$data);
//return $data;
}
and here is controller code:
$this->user_model->add_user();
$this->thank();
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'abc#gmail.com',
'smtp_pass' => '******',
'smtp_timeout' => '4',
'mailtype' => 'text',
'charset' => 'iso-8859-1'
);
$this->load->library('email',$config);
$this->email->from('mubbashir.azez#gmail.com');
$this->email->to($data['Email']);
$this->email->subject('test subject');
$this->email->message('hello CI');
$this->email->send();
echo $this->email->print_debugger();
here is view code:
<label for="email_address">Your Email:</label>
<?php echo form_error('email_address','<div class="error">', '</div>');?>
<input type="text" id="email_address" name="email_address" value="<?php echo set_value('email_address'); ?>" />
</p>
print debugger result:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: controllers/user.php
Line Number: 82
A PHP Error was encountered
Severity: Warning
Message: fgets() [function.fgets]: SSL: The operation completed successfully.
Filename: libraries/Email.php
Line Number: 1869
220 mx.google.com ESMTP ea4sm1055346wib.7 - gsmtp
hello: 250-mx.google.com at your service, [139.190.86.52]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
from: 250 2.1.0 OK ea4sm1055346wib.7 - gsmtp
to: 555 5.5.2 Syntax error. ea4sm1055346wib.7 - gsmtp
The following SMTP error was encountered: 555 5.5.2 Syntax error. ea4sm1055346wib.7 - gsmtp
data: 503 5.5.1 RCPT first. ea4sm1055346wib.7 - gsmtp
The following SMTP error was encountered: 503 5.5.1 RCPT first. ea4sm1055346wib.7 - gsmtp
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Wed, 12 Feb 2014 03:26:52 +0500
From: <mubbashir.azez#gmail.com>
Return-Path: <mubbashir.azez#gmail.com>
Subject: =?utf-8?Q?test_subject?=
Reply-To: "mubbashir.azez#gmail.com" <mubbashir.azez#gmail.com>
X-Sender: mubbashir.azez#gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <52faa3ac53dcf#gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_52faa3ac53dd9"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_52faa3ac53dd9
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
hello CI
--B_ALT_52faa3ac53dd9
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
hello CI
--B_ALT_52faa3ac53dd9--
The return value in your model must be
$data
and in your controller code:
replace this
$this->user_model->add_user();
with
$data = $this->user_model->add_user();
You have to put this into your controller:
$data=array(
'username'=>$this->input->post('user_name'),
'first_name' => $this->input->post('fname'),
'last_name' => $this->input->post('lname'),
'email'=>$this->input->post('email_address'),
'password'=>md5($this->input->post('password'))
);
Pass this $data to your model:
$this->user_model->add_user($data);
In your model also write:
add_user($data);
Then change this line also
$this->email->to($data['Email']);
to
$this->email->to($data['email']);
i was testing to send email by using codeigniter and i successfully send the email,but when i checked my inbox,i didn't find my email i send before.
here's controller:
$this->load->library('email');
$this->email->from('email#yahoo.com', 'my name');
$this->email->to('email#yahoo.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
success message:
Your message has been successfully sent using the following protocol: mail
From: "XXXXXXXXXXXXXX"
Return-Path:
Reply-To: "XXXXXXX#yahoo.com"
X-Sender: XXXXXXX#yahoo.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <XXXXXXX#yahoo.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
Testing the email class.
You may check your Spam folder in your email account.
Sometimes gmail/yahoo set email as spam when the mail send from local server.
Try using the following config...
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'your host',
'smtp_port' => 465,
'smtp_user' => 'your email address',
'smtp_pass' => 'password',
'mailtype' => 'html',
'mailpath' => '/usr/sbin/sendmail',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE;
);
$this->load->library('email', $config);
Depending on your server, you should also check your mail server logs to see if the email actually made it off the box. Sometimes you might have success sending it, as the mail is passed to EXIM on your server, but the mail might die in a queue.
If this is a linux box, typically start looking in /var/log/exim4/ etc; (of course depends on your mail server setup).
When I try to send emails from localhost, everything works fine. But when I uploaded my app to the server, the email functionality doesn't work anymore! I uses a Gmail account.
Here is my config/email.php file:
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'myemail#gmail.com';
$config['smtp_pass'] = 'my_password';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 80;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
$config['sender_name'] = 'Name';
$config['from_email'] = 'myemail#gmail.com';
$config['to_email'] = 'myemail#gmail.com';
$config['email_subject'] = 'Email Subject';
And this is how I sent an email in my controller:
$this->load->library('email');
$this->email->from($this->config->item('from_email'), $this->config->item('sender_name'));
$this->email->to($this->config->item('to_email'));
$this->email->subject($this->config->item('email_subject'));
$this->email->message($string);
if (!$this->email->send())
{
$data['success'] = FALSE;
}
else
{
$data['success'] = TRUE;
}
$this->_example_output('layouts/sendemail_confirm.php', $data);
And this is the error I receive:
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to
ssl://smtp.googlemail.com:465 (Connection refused)
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection refused)
It's possible that your server's IP address is blacklisted by Google due to previous spamming attempts... Is it a shared hosting account? A cloud hosting account? Etc? All those are susseptable to stuff like this.
There might also be a reverse DNS lookup mismatch with the domain name and from address, or the domain's DNS might have SPF policy settings that are preventing Google from accepting mail, or an envelop issue with the host-name, or it's using 127.0.0.1 as the originating address.
Also check your php.ini settings to make sure you are using / or not-using sendmail_from= and mail.add_x_header= the same way on both systems.
Try using smtp host as "smtp.gmail.com"
$config['smtp_host'] = 'smtp.gmail.com';
Use this config options
$config['protocol'] = 'smtp';
$config['mail_path'] = 'ssl://smtp.googlemail.com';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
And add this line, after loading email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'mail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'iskpro.it#gmail.com', // change it to yours
'smtp_pass' => 'afycon#123', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($from); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();