EllisLab text mark
Advanced Search
     
In need of Email code. . . 
Posted: 09 November 2012 05:12 AM   [ Ignore ]
Joined: 2012-11-02
5 posts

Hi, i need sample email code to check mail sending from my task. . .I had tried upto my level, but i dint get correct solutions. . .can u please give me some sample code to send mail from codeigniter framework. . .


I am waiting. . .Thanks in advance. . .


Regards,
Kasirajan.C

 Signature 

kasirajan

 
Posted: 09 November 2012 07:23 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-11-26
7 posts

Hi,

Try it: http://ellislab.com/codeigniter/user-guide/libraries/email.html

If you work locally, you may have problems with the SMTP. Configure email configurion files. Use this service:sendgrid.com

wink

 
Posted: 09 November 2012 08:19 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-11-02
5 posts
public function __construct()
{
parent
::__construct();
$this->load->model('model');
$this->load->library('session');
$this->load->helper('url');
}
$config 
= Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'user@abc.com'// change it to yours
'smtp_pass' => ' ur pwd here'// 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('user@abc.com'); // change it to yours
$this->email->to('user@abc.com'); // change it to yours
$this->email->subject('Email using Gmail.');
$this->email->message('Working fine ! !');

if(
$this->email->send())
{
return TRUE;
}
else
{
show_error
($this->email->print_debugger());
return 
FALSE;


This is my code. i had used this to send email..I had hosted the code in server,  but its not working in my server too. . . pls tel me the solution… thanks in advance. . .

 

 

 Signature 

kasirajan

 
Posted: 09 November 2012 08:32 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-11-26
7 posts

Note: Try it you will know logs.(Server LINUX -> /var/log/apache2/error.log)
View this post https://support.google.com/mail/bin/answer.py?hl=es&answer=14257 .
Also you could view this replys http://ellislab.com/forums/viewthread/84689/

 
Posted: 11 November 2012 12:23 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-09-04
7 posts

Hi

I had trouble with my server setup and using Codeigniter’s built-in email functions so I had to write my own library so I could send emails using PEAR. Feel free to use (and adjust as necessary) if you have similar issues:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Email_functions {
 
 
private $smtp_params = array();
 
 public function 
__construct() 
 
{
  
require_once "Mail.php";
  include(
'Mail/mime.php');
  
  
 
// Enter your SMTP authentication params here:
     
$this->smtp_params['host']     '';
     
$this->smtp_params['port']     '';
     
$this->smtp_params['auth']     '';
     
$this->smtp_params['username''';
     
$this->smtp_params['password''';
 
}
 
 
 
public function send_email($to,$from,$subject,$htmlBody,$attachment=NULL)
 

  
  $text 
str_ireplace("<br />","\n"$htmlBody); 
  
$text strip_tags($htmlBody);
  
$crlf "\n";
  
   
$headers = array ('From' => $from,
     
'To' => $to,
     
'Subject' => $subject);
     
    
// Creating the Mime message
       
$mime = new Mail_mime($crlf); 
       
      
// Setting the body of the email
     
$mime->setTXTBody($text);
     
$mime->setHTMLBody($htmlBody);
     if ( ! empty(
$attachment)) $mime->addAttachment($attachment);
 
     
$body $mime->get();
     
$headers $mime->headers($headers);
     
   
     
    
// Sending the email using smtp
        
$mail =& Mail::factory('smtp'$this->smtp_params); 
        
$mail->send($to$headers$body);
        
           
            
        if (
PEAR::isError($mail)) :
         return 
FALSE;
        else :
         return 
TRUE;
        endif;  

 
}
 
 
}
/* End of file Email_functions.php */ 
/* Location: ./application/libraries/email_functions.php */