I would like to send email using SMTP server with codeigniter - php

I'm try to sending email using SMTP server with codeIgniter
i have code and its working fine on localhost but not on server, i have done lots of research and try many code but it's still not working.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxx#gmail.com',
'smtp_pass' => 'xxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#gmail.com', 'Blabla');
$list = array('xxx#gmail.com','xxxxx#gmail.com');
$this->email->to($list);
$this->email->reply_to('xxxxx#gmail.com', 'Explendid Videos');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
$result = $this->email->send();
Error-
The following SMTP error was encountered: 111 Connection refused
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

please edit your autoload to
$autoload['libraries'] = array('database','email');
please advise if you are still getting an error...

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.

Sending Mail Using Gmail In Codeigniter

I will try to send mail using gmail in codeigniter. I write code as given bellow. When i upload it on c panel it will work properly for 2 days but after that it stop working.
//Load email library
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxx',
'smtp_pass' => 'xxxxxx',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype('html');
$this->email->set_newline("\r\n");
//Email content
$htmlContent = '<h1>MY WEBSITE</h1>';
$htmlContent .= '<p>OTP For Reset Your Password.</p>';
$this->email->to($uemail);
$this->email->from('xxxxxxxx','MyWebsite');
$this->email->subject('MESSAGE');
$this->email->message($htmlContent);
//Send email
$this->email->send();
I experienced the same thing where the email was not sent and there was no error, it turned out that when I checked my Gmail account it wasn't always on the Primary tab (make sure it wasn't in the Spam folder either). Sent but in the Promotions tab.

codeigniter send email working but not all the time

this is driving me crazy.... I have just uploaded a site with this email configuration for receiving message from the contact form:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.mysite.com',
'smtp_port' => 587,
'smtp_user' => 'noreply#mysite.com.ar',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from($data['ct_email'], "contact form");
$this->email->reply_to($data['ct_email']);
$this->email->to("prueba#mysite.com");
$this->email->bcc("noreply#mysite.com.ar"); //copy
$this->email->subject($data['ct_subject']);
$this->email->message($data['ct_message']);
$email = false;
if($this->email->send()){
$email = true;
}
return $email;
As you can see I have a .com and a .com.ar, My server is configured with the .com.ar account but I created an alias with the .com
The problem is that messages arrive in 1 to 10 messages sended...so that means it only works sometimes.
How can I solve this? I have tried changing email addresses but it's all the same...
I keep trying sending messages and it only send sometimes. For the ones that are not sended this is the error displayed:
-0300 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

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!

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.

Categories