Can't send email from gmail in codeigniter, SMTP Authentication error - codeigniter

I'm trying to send an email in codeigniter, but something wrong and i dont know how to fix it.
It success when I send in localhost, but when I upload my app into host, it cant send. This is my code
$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'] = 'username';
$config['smtp_pass'] = '****';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->send();
echo $this->email->print_debugger();
And this is my error when I submit an email
Failed to authenticate password. Error: 535 Incorrect authentication data
*from: 250 OK
to: 550-Please turn on SMTP Authentication in your mail client, or login to the
550-IMAP/POP3 server before sending your message. mb2d247.vdrs.net
550-(hanghieunara.com) [112.78.2.247]:51939 is not permitted to relay through
550 this server without authentication.*
The following SMTP error was encountered: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message.
mb2d247.vdrs.net 550-(hanghieunara.com) [112.78.2.247]:51939 is not permitted to relay through 550 this server without authentication.

See if your email account is not active with difinições security for external access, if you need to grant access to your site's SMTP server (your email address) so you can perform authentication.

To send smtp gmail autenticated with codeigniter
1 - Be sure if openssl in your php instalation is enabled.
2- This command is fundamental to script works: $this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'gmail.login#googlemail.com',
'smtp_pass' => 'your_password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('gmail.login#googlemail.com', 'Your Name');
$this->email->to('recipient#destination.tld');
$this->email->subject(' CodeIgniter Rocks Socks ');
$this->email->message('Hello World');
if (!$this->email->send())
show_error($this->email->print_debugger());
else
echo 'Your e-mail has been sent!';
Full solution link: https://ellislab.com/forums/viewthread/84689/

Related

i cant send mail codeigniter

I can't send mail from codeigniter to yandex mail when i using this code:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.yandex.com',
'smtp_port' => 465,
'smtp_user' => 'blablabla#yandex.com',
'smtp_pass' => 'blablabla',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'newline' => "\r\n"
);
$this->load->library('email');
$this->email->initialize($config);
$msg = $this->messages($f2, $f3);
$this->email->to($f1);
$this->email->subject('Here is Subject');
$this->email->message($msg);
if($this->email->send()){
echo "Masuk!";
}else{
echo "Gagal!";
}
echo $this->email->print_debugger();
And the result always says:
Gagal!Cannot send mail with no "From" header.
Cannot send mail with no "From" header.
You simply need to add a From address to your email, by calling
$this->email->from('your#example.com', 'Your Name');
or
$this->email->from('your#example.com');
Depending on the sending and receiving provider, that might get you in trouble though if you try and send the email under another From address, than the one you authenticated against the SMTP server with - it might get classified as spam then (or even rejected by the SMTP server right away) - so in this case here you should use blablabla#yandex.com as From.
you have to set a name and email as a sender.
for example if you set different email and name for sender it shows in inbox mail (Gmail for example) as like below image

mail codeigniter was sent,but not found in inbox

i was testing to send email by using codeigniter and i successfully send the email,but when i checked my inbox,i didn't find my email i send before.
here's controller:
$this->load->library('email');
$this->email->from('email#yahoo.com', 'my name');
$this->email->to('email#yahoo.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
success message:
Your message has been successfully sent using the following protocol: mail
From: "XXXXXXXXXXXXXX"
Return-Path:
Reply-To: "XXXXXXX#yahoo.com"
X-Sender: XXXXXXX#yahoo.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <XXXXXXX#yahoo.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
Testing the email class.
You may check your Spam folder in your email account.
Sometimes gmail/yahoo set email as spam when the mail send from local server.
Try using the following config...
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'your host',
'smtp_port' => 465,
'smtp_user' => 'your email address',
'smtp_pass' => 'password',
'mailtype' => 'html',
'mailpath' => '/usr/sbin/sendmail',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE;
);
$this->load->library('email', $config);
Depending on your server, you should also check your mail server logs to see if the email actually made it off the box. Sometimes you might have success sending it, as the mail is passed to EXIM on your server, but the mail might die in a queue.
If this is a linux box, typically start looking in /var/log/exim4/ etc; (of course depends on your mail server setup).

Email sent in localhost but not in server

When I try to send emails from localhost, everything works fine. But when I uploaded my app to the server, the email functionality doesn't work anymore! I uses a Gmail account.
Here is my config/email.php file:
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'myemail#gmail.com';
$config['smtp_pass'] = 'my_password';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 80;
$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;
$config['sender_name'] = 'Name';
$config['from_email'] = 'myemail#gmail.com';
$config['to_email'] = 'myemail#gmail.com';
$config['email_subject'] = 'Email Subject';
And this is how I sent an email in my controller:
$this->load->library('email');
$this->email->from($this->config->item('from_email'), $this->config->item('sender_name'));
$this->email->to($this->config->item('to_email'));
$this->email->subject($this->config->item('email_subject'));
$this->email->message($string);
if (!$this->email->send())
{
$data['success'] = FALSE;
}
else
{
$data['success'] = TRUE;
}
$this->_example_output('layouts/sendemail_confirm.php', $data);
And this is the error I receive:
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to
ssl://smtp.googlemail.com:465 (Connection refused)
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection refused)
It's possible that your server's IP address is blacklisted by Google due to previous spamming attempts... Is it a shared hosting account? A cloud hosting account? Etc? All those are susseptable to stuff like this.
There might also be a reverse DNS lookup mismatch with the domain name and from address, or the domain's DNS might have SPF policy settings that are preventing Google from accepting mail, or an envelop issue with the host-name, or it's using 127.0.0.1 as the originating address.
Also check your php.ini settings to make sure you are using / or not-using sendmail_from= and mail.add_x_header= the same way on both systems.
Try using smtp host as "smtp.gmail.com"
$config['smtp_host'] = 'smtp.gmail.com';
Use this config options
$config['protocol'] = 'smtp';
$config['mail_path'] = 'ssl://smtp.googlemail.com';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
And add this line, after loading email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'mail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'iskpro.it#gmail.com', // change it to yours
'smtp_pass' => 'afycon#123', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($from); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();

How do I send email to local system using xamp and windows7 in codeigniter?

I'm trying to run this code :
$this->load->library('email');
$this->email->from('anu1488#gmail.com', 'Anudeep');
$this->email->to('anu1488#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
When I tried to send, I got this error:
A PHP Error was encountered
Severity: Warning
Message: mail() [function.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: 1553
What caused this? How can I resolve it?
It sounds like you do not have an SMTP server (mail server) set up on your local machine to send out email. It sounds like the libraries/Email.php file is referencing a hostname/port where a valid mail server does not live.
**I guess you need to setup email configuration and port number in config/email .**
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='abhi.abc#gmail.com';
$config['smtp_pass']='password';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['mailtype'] = "html";
**if every thing is correct from your side then you can just change 'smtp_port' number and then check it definitely it will work`enter code here`.**
try this,its working for me....
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'user#gmail.com',
'smtp_pass' => 'user password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('user#gmail.com', 'User');
$this->email->to(sample#gmail.com);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if ($this->email->send()) {
$data['error'] = "Your email was sent";
} else {
show_error($this->email->print_debugger());
}
then open your php.ini and go to extension=php_openssl.dll and un comment this line .
after that restart ur wamp server.

Codeigniter SMTP Email with Amazon SES

I think yesterday Amazon announced SMTP support for SES (Simple Email Service).
I tried to send SMTP email with Codeigniter with no luck.
I have a verified sender and everything looks good:
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.us-east-1.amazonaws.com',
'smtp_user' => 'SMTP USERNAME',
'smtp_pass' => 'SMTP PASSWORD',
'smtp_port' => 465,
'mailtype' => 'html'
);
$this->email->initialize($config);
$this->email->print_debugger();
$this->email->from('verified_email_address#something.com', 'Test From');
$this->email->to('email#example.com', 'Test To');
$this->email->subject('Test');
$this->email->message('test');
$this->email->send();
I tried the folowing smtp_host:
email-smtp.us-east-1.amazonaws.com
tls://email-smtp.us-east-1.amazonaws.com
ssl://email-smtp.us-east-1.amazonaws.com
When i echo the print_debugger() i get:
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-194655181
hello: 421 Timeout waiting for data from client.
These tests run on a mediatemple (gs) server.
I got that timeout message until I added the line:-
$this->email->set_newline("\r\n");
I have my host set as ssl://email-smtp.us-east-1.amazonaws.com
You need to do 3 things to get CI to work with Amazon Simple Email Service (SES)
Need to set newline = \r\n or you will get a timeout.
Need to set smtp_crypto to something. (New requirement)
Need to make sure "from" email address is approved in Amazon SES. I made my "from" email address "no-reply#mydomain.com"
Additionally, you should set up DKIM for your "from" email address to prevent emails from getting put in spam folders. This involves going into Amazon SES -> Identity Management -> Email Addresses -> DKIM, hitting the enable button, and adding 3 DNS entries to your website's DNS.
No need to do anything special to set up SPF. The envelope domain amazonses.com passes SPF.
Finally, make sure to use "reply-to" if you want users to be able to reply to an e-mail address different from your approved "from" e-mail address.
Example working code:
$obj = &get_instance();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'email-smtp.us-west-2.amazonaws.com';
$config['smtp_user'] = 'USER';
$config['smtp_pass'] = 'PASS';
$config['smtp_port'] = '587';
$config['newline'] = "\r\n";
$config['smtp_crypto'] = 'tls';
$obj->email->initialize($config);
$obj->email->set_mailtype('html');
// don't html_escape email header variables
$obj->email->from(MV_FROM_EMAIL, $from_name);
$obj->email->reply_to($from_email, $from_name);
$obj->email->to($to);
$obj->email->subject($subject);
$obj->email->message($obj->load->view($path, html_escape($data), true));
$obj->email->send();
public function enviar_email($para, $assunto, $mensagem, $formato='html'){
$this->CI->load->library('email');
$config['mailtype'] = $formato;
$config['useragent'] = 'Post Title';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'tls://email-smtp.us-east-1.amazonaws.com';
$config['smtp_user'] = 'smtpuser';
$config['smtp_pass'] = 'smtppass';
$config['smtp_port'] = '465';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$this->CI->email->initialize($config);
$this->CI->email->from('Your Verified Sender Email', 'Post Title');
$this->CI->email->to($para);
$this->CI->email->subject($assunto);
$this->CI->email->message($mensagem);
if($this->CI->email->send()):
return TRUE;
else:
$this->CI->email->print_debugger();
endif;
}
I also needed to add the line
$config['smtp_crypto'] = 'tls';
to my config array
this is supported by CI 2.1.0 and greater
The setup that worked for me looks like this:
$test_config['protocol'] = 'smtp';
$test_config['smtp_host'] = 'ssl://email-smtp.us-east-1.amazonaws.com';
$test_config['smtp_port'] = '465';
$test_config['smtp_user'] = 'XXXXXXXXXXXXXXXXXXX';
$test_config['smtp_pass'] = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY';
$test_config['newline'] = "\r\n";
$this->email->initialize($test_config);
$this->email->from('from#test.com', 'From at Test.com');
$this->email->to('To#Test.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
The newline character must be set to "\r\n", and can bet set in the config file, if properly set as "\r\n", not '\r\n' as noted above.

Resources