Codeigniter email sending no "To" on print_debugger(); - codeigniter

My code:
$config['protocal'] = 'smtp';
$config['mail_path'] = 'ssl://smtp.googlemail.com';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'mygmail#gmail.com';
$config['smtp_pass'] = 'mypass!';
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$this->load->library('email', $config);
$config['newline'] = "\r\n";
$this->email->initialize($config);
$this->load->library('email');
$this->email->from('info#maaden.com.sa','Blowing Notification');
$this->email->to('eduardodbarrete#gmail.com');
$this->email->cc('eduardobarrete#gmail.com');
$this->email->subject('Whistle Receipt');
$message = "<p> Thank you for the report you submitted </p>";
$message .= "<p> Report ID: <strong>" . $session_id . "</strong></p>";
$message .= "<p> Your Email: <strong>" . $this->input->post('email') . "</strong></p>";
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
Th print_dubugger(); output below;
Your message has been successfully sent using the following protocol: mail
User-Agent: CodeIgniter
Date: Tue, 8 Oct 2013 12:13:46 +0300
From: "Blowing Notification"
Return-Path:
Cc: email.com.sa
Reply-To: "no-reply#email.com"
X-Sender: no-reply#email.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5253ccca8ee37#email.com.sa>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5253ccca8eeae"
On the above print_debugger(); output i don't see any "To" where should my email go. Maybe the reason why i didn't receive any email. Thanks

You need to config your smtp server information like this:
$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', $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();

Related

Email sent but not received

The result from email sending is true but email is not received. My configs looks like this:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587,
'smtp_user' => 'tomaivanovtomov#gmail.com',
'smtp_password' => 'abc9110033969qwe',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'smtp_timeout' => 10,
'smtp_crypto' => 'tls'
);
$this->load->library('email', $config);
If I try the other way with $this->email->initialize($config) and $this->load->library('email') before it, when try to send it I get an error:
fsockopen(): unable to connect to smtp.gmail.com:587 (Connection refused)
Try to modify the connection to use ssl instead of tls, and port 465 instead of 587 :
'smtp_port' => 465,
'smtp_crypto' => 'ssl'
Change smtp host with
'smtp_host' => 'ssl://smtp.gmail.com',
Check you smtp_port and provide correct your port number with
'smtp_port' => 587,
And change crypto type with ssl
'smtp_crypto' => 'ssl'
try to do it in following order.
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'abcdef#gmail.com'; //your email address
$config['smtp_pass'] = 'testingmails'; // password
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$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;
$this->email->initialize($config);

How to send a mail using gmail smtp in codeigniter

I want to send an email from my Gmail account through the website. how do I do that? I've tried every possible way but couldn't get the desired output.
public function mailuser(){
$config = Array(protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com','smtp_port' => 465,'smtp_user' => 'xxxx#gmail.com','smtp_pass' => 'xxxx','mailtype' => 'html');
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
if($this->email->send()){
echo 'Success email Sent';
echo $this->email->print_debugger();
}
else{
echo 'Email Failed To Send';
echo $this->email->print_debugger();
}
}
I think you are using wrong parameters in config like ssmtp
protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com'
Your config array should look like :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx#gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
$result = $this->email->send();
Also verify to enable extension extension=php_openssl.dll in php.ini.
if not please remove ;

Send email with Gmail not work | codeigniter

this is my code to send email with gmail but it is not work , I am try hard to make it work for 4 days but still not work.
please help me, it was work before 6 day , after that not work , the server told me to change PHPMailer to SMTP Gmail , I am changed but still not work ...
i am register in Amazon SES Email , but i do not know how to use it, so i have 2 option : make this run in my normal server or change to Amazon SES , if SES is better chance learn me how to use it .
my site to test
my Controller
public function Send_Single_Email_Try ()
{
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'xx#gmail.com',
'smtp_pass' => 'xx',
'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();
if($send)
{
echo 1;
}
else
{
echo 0;
}
}
my JS
$(document).on('click','#SendEmailTry',function(e){
e.preventDefault();
$.ajax({
url:"<?php echo
base_url('Email/Send_Single_Email_Try/')?>",
type: "POST",
dataType: "text",
success:function(data)
{
if (data == 1)
{
alert("send");
}
else
{
alert("notsend");
}
},
error: function (jqXHR, textStatus, errorThrown)
{
alert("error")
}
});
});
Try this....
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'sender_mailid#gmail.com';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('sender_mailid#gmail.com', 'sender_name');
$this->email->to('recipient#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
check and set your csrf protection from your site config file(yourproject/config/config.php) such as,
$config['csrf_protection'] = FALSE;
your rewrite code:
public function Send_Single_Email_Try ()
{
$this->output->enable_profiler(FALSE);
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'xx#gmail.com',
'smtp_pass' => 'xx',
'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');
$send = $this->email->send();
if($send)
{
echo 1;
}
else
{
echo 0;
}
}

config email library for send email in codeigniter

I have a code in controller codeigniter framework as follows :
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
$this->load->library('email');
$this->email->from('example#yahoo.com', 'example');
$this->email->to('example#gmail.com','example');
$this->email->subject('my Subject');
$this->email->message('my Message');
if ($this->email->send())
echo "Mail Sent!";
else
echo "There is error in sending mail!";
}
}
This code correctly sends email . but when that i am config email class setting , this code not work and not send email . for example follow code will not send email :
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
$this->load->library('email');
$this->email->from('example#yahoo.com', 'example');
$this->email->to('example#gmail.com','example');
$this->email->subject('my Subject');
$this->email->message('my Message');
$config['protocol'] = 'sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
if ($this->email->send())
echo "Mail Sent!";
else
echo "There is error in sending mail!";
}
}
Please tell me where is the problem .
thanks .
Protocol can be Sendmail, SMTP and mail.
You should load library after configuration:
$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");
$this->email->from('example#yahoo.com', 'example');
$this->email->to('example#gmail.com','example');
$this->email->subject('my Subject');
$this->email->message('my Message');
if ($this->email->send())
{
echo "Mail Sent!";
}
else
{
echo "There is error in sending mail!";
}

Send email by codeigniter

I am using codeigniter to send email.
function forget_pw() {
$this->load->library('email');
$config['smtp_host'] = 'host address';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = 'password';
$this->email->initialize($config);
$this->email->from('admin#email.com', 'Admin');
$this->email->to('test#yahoo.com.hk');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
}
No any error show in console. But the email didn't send out.
You can create a function like this:
public function sendEmail($subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'xxxxx.xxxxxx.xxxxx',
'smtp_port' => 465,
'smtp_user' => 'xxxxx.xxxxxx.xxxxx',
'smtp_pass' => 'xxxxx.xxxxxx.xxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxxx.xxxxxx.xxxxx');
$this->email->to('xxxxx.xxxxxx.xxxxx');
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
And use it like this $this->sendEmail('Title', 'Message'); Good luck

Resources