Say Email sent but nothing is recieved when sent email using Codeigniter - php

I have used this several ways but can't seem to get it working. I am running it on live server.
I am using bigrock hosting and as per their document it says just use "localhost" as smtp host. Link
It says email sent but I get nothing..
public function index() {
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'localhost',
'smtp_port' => '587',
// Other way it say Email sent
//'smtp_host' => 'ssl://localhost',
//'smtp_port' => '465',
'smtp_user' => 'support#abc.com',
'smtp_pass' => 'sdfsfsdfsd'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('support#abc.com', 'ABC');
$this->email->to('abc#gmail.com');
$this->email->subject('Test');
$this->email->message('Success');
if ($this->email->send()) {
echo 'Email Sent';
} else {
show_error($this->email->print_debugger());
}
}
Thanks in advance.

This line: $this->email->to('abc#gmail'); make it 'abc#gmail.com' and make sure it is existing..If it still doesn't work, try a legit email from inside you email->from.

Related

Codeigniter 3 Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

public function send_mail_verification(){
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => '587',
'smtp_crypto' => 'tls',
'smtp_user' => 'myacc#gmail.com',
'smtp_pass' => 'mypass',
'charset' => 'iso-8859-1'
);
$this->email->initialize($config);
$this->email->from('myemail3#gmail.com', 'Registration');
$this->email->to('tosomeonemail#gmail.com');
$this->email->subject('something');
$this->email->message('Testing email.');
if($this->email->send()){
echo "success";
}
else{
show_error($this->email->print_debugger());
}
}
I've been looking at other solution that I find in the internet and none of them worked for me.
I've also tried the mail function and changed some things in sendmail.ini and php.ini in xampp and that worked. However, the send mail configuration in codeigniter-3 is much better if I'm going to share my code to other so that they don't need to change some configuration in their sendmail.ini and php.ini. What do you think causes the error?
$this->email->set_newline("\r\n");
I added this one and it worked... wonder why.

Why aren't my emails sending from CodeIgniter?

My codeigniter script will not send emails. I have tested sendmail on xampp with a native PHP email script and it works. This is definitely a problem with CI or my config. The send() function always returns false and the print_debugger() function is always blank. Am I doing something wrong?
<?php
$config = array(
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'myaccount#gmail.com',
'smtp_pass' => '#############',
'smtp_port' => '465'
);
$this->load->library('email', $config);
$this->email->from($this->stg['site_name']);
$this->email->to($this->input->post('email_address'));
$this->email->subject('Your Account Email Has Been Changed');
$data = array(
'activation_code' => $this->member->activation_code
);
$message = $this->load->view('emailTemplates/change_email', $data, true);
$this->email->message($message);
if(!$this->email->send()){
$this->template->overallHeader('Email Failed');
$data = array(
'title' => 'Email Sending Failed',
'message' => 'The system failed to dispatch the email message to your new email address. Because of this, the email address on your account has NOT been changed. '.$this->email->print_debugger()
);
$this->load->view('errorBody', $data);
} else {
//do stuff
}
I have also tried static strings instead of the form input variables as the to and from, etc.

SMTP success but the email is not delivered

I'm a newbie to CodeIgntier. I'm trying to setup SMTP on CodeIgniter. I receive a success message on page but email is not delivered. Can somebody help me?
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->from('xxx#gmail.com', 'Admin Team');
$sendTo = $this->input->post('email');
$message= 'Hello';
$this->email->to($sendTo);
$this->email->subject('Verification Email');
$this->email->message($message);
if($this->email->send()){
echo "Success";
}
You have mentioned xxx#gmail.com. In google there is Security protection call 2-Step Verification. Make sure its there,If there remove it and try
There is no fault in your code. . To remove it check this link
your code seems ok, make sure your server has openssl extension up and running , and check your firewall for the used smtp port (465 in your case). I would also recommend you using the third party library phpmailer from https://github.com/ivantcholakov/codeigniter-phpmailer whic (mostly for sending html in your message and links )
cheers!

PHP Email sending. Works on http://localhost/ but not on http://{IP ADDRESS}/

I am using this code for sending email from localhost. Its in codeIgniter. My OS is Ubuntu 14.XX
function email()
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '*****#gmail.com', // change it to yours
'smtp_pass' => '*****', // change it to yours
'mailtype' => 'html',
'charset' => 'UTF-8',
);
$message = 'aggasdgsd';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('*****#gmail.com'); // change it to yours
$this->email->to('****#gmail.com');// change it to yours
$this->email->subject('Rdfgsdfgf ing');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Email gets delivered when I use URL http://localhost/ci_project/email BUT
It doesn’t work if I use URL http://10.10.10.XX/ci_project/email, Also there is no error message.
Have any idea, Why it is working when use localhost in URL & Not working when i use IP address in URL ??
Check if there is email server working on server or not. if you are using sendmail then try this command on server
service sendmail restart
Is ssl enable on your PHP config?
check if you have the following line in your php.ini
extension=php_openssl.dll

Codeigniter email - browser keeps on loading

I am trying to send email using codeigniter.
<?php
class email_page extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$config = Array(
'protocol'=>'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'testmail#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email', $config);
$this->email->set_newline('\r\n');
$this->email->from('testmail#gmail.com','Sender name');
$this->email->to('testmail#gmail.com');
$this->email->subject('Test mail');
$this->email->message('This is a test mail from codeigniter');
if($this->email->send()){
echo "Your mail was sent successfully!!!";
}
else{
show_error($this->email->print_debugger());
}
}
}
The page keeps on loading and does not give any result. The code looks fine to me. Are there any errors? Thanks
change your account settings here
https://www.google.com/settings/security/lesssecureapps
I myself found the answer.
$this->email->set_newline('\r\n');
Changed the above line to
$this->email->set_newline("\r\n");
I am not sure how this can happen.
i have found error, just change port to 25
function test(){
$config = Array(
'protocol'=>'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => '25',
'SMTPAuth' => true,
'smtp_user' => 'email#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email', $config);
//$this->email->set_newline('\r\n');
$this->email->from('email#gmail.com','Sender name');
$this->email->to('email#micromerger.com');
$this->email->subject('Test mail');
$this->email->message('This is a test mail from codeigniter');
//print_r($this->email);exit;
if( ! $this->email->send()){
//print_r("234");exit;
echo "Your mail was sent successfully!!!";
}
else{
//print_r("345");exit;
show_error($this->email->print_debugger());
}
}

Categories