SMTP success but the email is not delivered - php

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!

Related

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.

I would like to send email using SMTP server with codeigniter

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...

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

Mailing Service

I am doing a project using Codeigniter (Mobile Website). I want users to receive mails such as registration, forgot password, newsletters etc. Currently what I am doing is like :
function sendEmail($email) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'user#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('user#gmail.com', 'user');
$this->email->to($email);
$this->email->subject('Thank You for Registering');
$this->email->message('Thank You for Registering .');
if($this->email->send()){
echo "Success";
}
else {
echo "failed";
}
}
This works well. But is this the right way of doing things when you want to send mails of 2-3 types ? Please help me on this.
I would recommend to create email.php file in ./application/config folder and put your config array in that file. So when you change your email settings it will reflect in entire application. For more details visit Email class in codeigniter.
I would recommend not using Gmail smtp for a web application in production. Instead use premium (paid) services like www.mailgin.com where you can also use your own domain for sending, etc.
Or set up your own email server.
I would also recommend using a framework for sending the emails, for example www.swiftmailer.org

Categories