Welcome Guest, Not a member yet? Register   Sign In
In need of Email code. . .
#1

[eluser]kasirajan PHP[/eluser]
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
#2

[eluser]robertorubioes[/eluser]
Hi,

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

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

Wink
#3

[eluser]kasirajan PHP[/eluser]
Code:
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' => '[email protected]', // 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('[email protected]'); // change it to yours
$this->email->to('[email protected]'); // 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. . .



#4

[eluser]robertorubioes[/eluser]
Note: Try it you will know logs.(Server LINUX -> /var/log/apache2/error.log)
View this post https://support.google.com/mail/bin/answ...swer=14257.
Also you could view this replys http://ellislab.com/forums/viewthread/84689/
#5

[eluser]JoJo17[/eluser]
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:

Code:
<?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 */





Theme © iAndrew 2016 - Forum software by © MyBB