can't send email from localhost using codeigniter (blank page) - php

I'm about new at sending email using CodeIgniter. I have searched any tutorial and forum to handle send email using CodeIgniter, but none of them works for me. Hope someone can help.
This is the controller I use:
function send_email() {
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx#gmail.com',
'smtp_pass' => '****',
'mailtype' => 'text',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '';
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com');
$this->email->to('xxxx#gmail.com');
$this->email->subjects('Email Testing');
$this->email->message($message);
if($this->email->send()) {
echo 'Email sent!';
} else {
show_error($this->email->print_debugger());
}
}
I have edited php.ini as forum said, such as:
;For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail
; ... or under UNIX:
;
; extension=msql.so
extension=php_openssl.dll
I work Apache/2.2.22 (Ubuntu) Server.
And it shows blank page when I try to call the function. Is there any config to edit? Please give your suggestion. Thank you.
Updated:
This is the display_errors and error_reporting I edited in php.ini :
; display_errors
Default Value: On
Development Value: On
Production Value: On
; error_reporting
Default Value: E_ALL & ~E_NOTICE
Development Value: E_ALL | E_STRICT
Production Value: E_ALL & ~E_DEPRECATED

try this in codeigniter!!
public function sendEmail($email,$subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xyz#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xyz#gmail.com');
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
public function send_email()
{
$email="abc#gmail.com";
$subject="Your subject";
$message="You can write html tags in this message";
$this->sendEmail($email,$subject,$message);
}

use PHPMailer its easy
$this->load->library('PHPMailer/PHPMailer');
$mail=new PHPMailer(); //creat PHPMailer object
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; //needs login information
$mail->SMTPSecure = "tls"; //specifies tls security
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; //gmail smtp port
$dd3=$this->db->query("select * from email where eid=1")->row_array();;
/******************* Set Your Credentials********************/
$mail->Username = 'xxxx'; //SMTP gmail address
$mail->Password = 'xxx'; // SMTP account password
$mail->From = 'xxx'; //sender's gmail address
$mail->FromName = "from";
$mail->AddAddress("to");//receiver's e-mail address
$mail->Subject = $subject;//e-mail subject
$mail->Body ="message";//e-mail message
$mail->WordWrap = 50;
if(!$mail->Send())
{
$status='Message was not sent.';
}
else
{
$status='Message has been sent.';
// echo $status;
}

Related

codeigniter smtp mail not working properly

I have use gmail smtp email library to send mail from codeingiter project.
But it shows below error while submit form:
A PHP Error was encountered
Severity: Warning
Message: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1902
Backtrace:
File: D:\xampp\htdocs\projectName\application\controllers\Users.php
Line: 66
Function: send
File: D:\xampp\htdocs\projectName\index.php
Line: 315
Function: require_once
My controller function code:
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587, //if 80 dosenot work use 24 or 21
'smtp_user' => '**',
'smtp_pass' => '**',
'_smtp_auth' => true,
'smtp_crypto' => 'tls',
'protocol' => 'smtp',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('users#gmail.com'); //same email u use for smtp_user
$this->email->to($this->input->post('user_email'));
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
My php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=localhost
; http://php.net/smtp-port
smtp_port=25
But still mail not send.
Is there any problem with my controller.
The issue with your code is that you are not initializing the email setting. Your controller code on line $this->load->library('email', $config); is wrong. You have to initialize the email setting separately after the email library is loaded.
Take a look at this code.
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = 587, //if 80 dosenot work use 24 or 21
$config['smtp_user'] = '**';
$config['smtp_pass'] = '**';
$config['_smtp_auth'] = true,
$config['smtp_crypto'] = 'tls';
$config['protocol'] = 'smtp';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('users#gmail.com'); //same email u use for smtp_user
$this->email->to($this->input->post('user_email'));
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
For more information look at here

How can I get fix this error of this email issue with codeigniter? [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a problem like this.I want to send a mail from my web application so I put this in my controller.
$from_email = "tharuwan40#gmail.com";
$to_email = "warimali94#gmail.com";
//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Info');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
This web application is still running on localhost.I tried so many examples in the net and which have been posted in stack overflow tooo.But there was nothing on my mail.Email was not send.How can I get fix this?
Create config array
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
'wordwrap' => TRUE
);
then
$this->load->library('email', $config);
$this->email->from('mygmail#gmail.com', 'myname');//your mail address and name
$this->email->to('target#gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
if($this->email->send()) //sending mail
{
echo 'Mail sent';
}
else
{
print_r($this->email->print_debugger(), true);
}
Configuration in sendmail.ini
path [xampp folder]\sendmail\sendmail.ini
Configurations
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail#gmail.com
auth_password=yourgmailpassword
force_sender=myemail#gmail.com
open php.ini config file and search for[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Restart Server
Main Source

sending email using codeigniter email class

i have an error by trying to send an email using codeigniter email Class.
I have an error of :
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
How can i test to send email in codeigniter?. I am also using localhost. Is this problem only occurs when i use localhost?
Here is my code:
public function emailme() {
$this->load->library('email');
$message = $this->input->post('email_msg');
$this->email->from('iamjohnx3303#yahoo.com', 'John');
$this->email->to('iamjohnx3302#gmail.com');
$this->email->subject('Email Test');
$this->email->message($message);
$this->email->send();
}
Configuration in sendmail.ini
path c:\xampp\sendmail\sendmail.ini
Configurations
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail#gmail.com
auth_password=yourgmailpassword
force_sender=myemail#gmail.com
in php.ini
pathc:\xampp\xampp\php\php.ini
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
then
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
'wordwrap' => TRUE
);
$this->load->library('email', $config);
Mail Settings in XAMPP(Important)
$this->email->from('mygmail#gmail.com', 'myname');//your mail address and name
$this->email->to('target#gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
$this->email->send(); //sending mail
Use this before your send mail script
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount#YourDomain.com');

Code igniter email functionality

I am using codeigniter for my web application and i use the codeigniter's email functionality to send email. But I occurred the following error when i try to send the email.
Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP
This is the code i used to gain the functionality.
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.googlemail.com";
$config['smtp_port'] = 465;
$config['smtp_user'] = "xxxx#gmail.com";
$config['smtp_pass'] = "xxxxxx";
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com','Sample');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('temperary Email');
$this->email->message('This is a sample message');
if ($this->email->send()) {
echo 'Your email was sent, dude.';
} else {
show_error($this->email->print_debugger());
}
What is wrong with this?
Thanks..
Open ssl should be enabled.
have a look here http://www.devcha.com/2010/01/php-fsockopen-unable-to-connect-ssl.html
Or you can load the parameter in array:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$result = $this->email->send();
This works for me
I had some "crazy" problems using the CI´s default email library to send emails through SSL/TLS authenticated SMTP servers. I ended up using PHPMailer instead.

Send email by Email Class in codeigniter with Gmail

I want send a email by Email Class in codeigniter with gmail, but i get following error:
Error:
A PHP Error was encountered Severity: Warning Message:
mail() [function.mail]: Failed to connect to mailserver at
"ssl://smtp.googlemail.com" port 25, verify your "SMTP" and
"smtp_port" setting in php.ini or use ini_set() Filename:
libraries/Email.php Line Number: 1553
This is my full function in controll:
function send_mail(){
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'xyz#gmail.com';
$config['smtp_pass'] = 'xxxxxxx';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('neginph#gmail.com', 'Negin Phosphate Shomal');
$this->email->to('neginfos#yahoo.com');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
if($this->email->send())
{
echo 'Your email was sent, successfully.';
}
else
{
show_error($this->email->print_debugger());
}
}
I changed SMTP in php.ini as this:
SMTP = ssl://smtp.googlemail.com smtp_port = 25
What do i do?
With respect
this is what worked for me
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', $email_config);
$this->email->from('someuser#gmail.com', 'invoice');
$this->email->to('test#test.com');
$this->email->subject('Invoice');
$this->email->message('Test');
$this->email->send();
Have you turned on php_openssl?
Try to uncomment extension=php_openssl.dll in your php.ini file.
This is working for me on localhost:
<?php
class Email extends CI_controller
{
function index()
{
$this->load->library('email');
$this->load->helper('url');
$this->load->helper('form');
$config= Array(
'protocol' =>'localhost',
'smtp_host' => 'localhost',
'smtp_port' => 'localhost',
'smtp_user'=> 'root',
'smtp_pass' =>''
);
$this->load->library('email','$config');
$this->email->set_newline("\r\n");
$this->email->from('nisha#gmail.com','nisha');
$this->email->to('cse1473#gmail.com');
$this->email->subject('this is email with subject');
$this->email->message('it s working properly');
if($this->email->send())
{
echo "your email send";
}
else
{
show_error($this->email->print_debugger());
}
}
}
?>

Categories