login registration and verify email (gmail) codeigniter - codeigniter

I have problems when sending email, I make registration and verification by email, when on localhost everything runs smoothly, there are no problems, but when I am hosting, the email function cannot, please help
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'email#gmail.com', // change it to yours
'smtp_pass' => 'mypassword', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = "
<html>
<head>
<title>Verifikasi Kode</title>
</head>
<body>
<h2>Terima kasih telah berpartisipasi.</h2>
<p>Akun anda:</p>
<p>Email: ".$email."</p>
<p>Untuk melanjutkan pendaftaran, mohon klik link yang kami berikan</p>
<h4><a href='".base_url()."register/aktivasi/".$id."'>Activate My Account</a></h4>
</body>
</html>
";
$this->email->initialize($config);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($config['smtp_user']);
$this->email->to($email);
$this->email->subject('Signup Verification Email, abcd.com | No reply');
$this->email->message($message);
if($this->email->send()){
$this->session->set_flashdata('msg','Kode Aktivasi telah dikirim ke email, mohon di cek');
}
else{
$this->session->set_flashdata('msg', $this->email->print_debugger());
}
redirect('register',$data);
}
Error : Failed to authenticate password. Error: 534-5.7.14 Please 534-5.7.14 log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 18sm13749594pfp.100 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

This issue causes when your access is wrong.
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.googlemail.com', # Change
'smtp_port' => 587, # Change
'smtp_user' => 'email#gmail.com',
'smtp_pass' => 'mypassword',
'smtp_crypto' => 'tls', # Add
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
Make sure: Less secure apps enabled in Gmail and Turn off 2-Step Verification is turned off

You should change the “Access for less secure apps” to Enabled (it will be disabled, changed to enabled). Try it.

Related

I am not able to send mail using CodeIgniter email library using amazon SES

I have hosted my domain on amazon ec2 and i have added outbound rules for https (465) and custom tcp (587).
below are my email configuration
$config['email_config'] = [
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_host' => 'ssl://email-smtp.ap-south-1.amazonaws.com',
'smtp_port' => '587',
'smtp_user' => 'AKIAZJ2TDSA******',
'smtp_pass' => 'B*****N/aBD2mH3nWT4DiOfJ9NI3NRh*******',
'smtp_crypto' => 'tls',
'newline' => "\r\n"
];
And below are email sending code
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->reply_to($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to('k3#vaksys.com');
$this->email->subject('test subject');
$this->email->message("test");
if ($this->email->send())
{
// echo $this->email->print_debugger();
echo ' sent';
}
else
{
echo 'not sent';
}
According above code, it always goes to if condition.
what is the response from the server ? please put echo $this->email->print_debugger(); in the else{}.
the smtp_host started with ssl:// , the encryption is really done on tls ?
you set mailtype to html and the message not including html body (<html><head><title>test</title></head><body></body>Lorem ipsum dolor sit amet</html>).

In plesk server Codeigniter Mail Function not working with gmail on server side but good in localhost?

Everything going great on Codeigniter localhost but on particuler Plesk Linux Server I get the different type of error as per changing the port number and protocols. I'm really hanging on this problem, also read the documentation of Plesk but I didn't understand. Hope on StackOverflow someone gives a solution.
I tried most of the all port and protocols to get the result but not succeded. Used code
function sendMail()
{
$this->load->library('email');
// ini_set('SMTP', "smtp.rediffmailpro.com");
// ini_set('smtp_port', "25");
// ini_set('sendmail_from', "myemailid");
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$config = array(
// for rediff mail setup
// 'protocol' => 'smtp',
// 'smtp_host' => 'smtp.rediffmailpro.com',
// 'smtp_port' => 587,
// 'smtp_user' => 'email.com',
// 'smtp_pass' => 'pass',
// 'mailtype' => 'html',
// 'charset' => 'iso-8859-1', //'UTF-8'
// 'wordwrap' => TRUE
// for gmail setup
'protocol' => 'smtp', //'mail', 'sendmail', 'tls' tried these but get different type of errors
'smtp_host' => 'smtp.gmail.com', /*'smtp.googlemail.com',*/
'smtp_port' => 587, //465
'smtp_user' => 'user email',
'smtp_pass' => 'user pass',
//'smtp_crypto' => 'smtp',
'mailtype' => 'html',
'smtp_timeout' => 5,
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->email->initialize($config);
$this->load->library('email', $config);
$this->email->from('email','AG'); // change it to yours
$this->email->to('your email');// change it to yours
$this->email->subject('Test Mail');
$this->email->message('Dont be pannic.');
$this->email->set_newline("\r\n");
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
At this condition I get this error
Failed to authenticate password. Error: 534-5.7.14 Please log
534-5.7.14 in via your web browser and then try again. 534-5.7.14
Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754
k11sm2916535wmk.45 - gsmtp Unable to send email using PHP SMTP. Your
server might not be configured to send mail using this method.
But on given google url didn't get any idea about my problem or I didn't get it.
After changing
port 465,
smtp_hot "ssl://email.com",
Get this error
Failed to authenticate password. Error: 534-5.7.14 Please log
534-5.7.14 in via your web browser and then try again. 534-5.7.14
Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754
y66sm2047426wmd.37 - gsmtp Unable to send email using PHP SMTP. Your
server might not be configured to send mail using this method.
I don't understand what am I doing wrong.
Want to successfully send mail. On Plesk server

fsockopen(): unable to connect to ssl://smtp.gmail.com:465

$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => '465',
'smtp_user' => "xxxxxxx#gmail.com",
'smtp_pass' => "xxxxxxx", // change it to yours
'mailtype' => 'html',
'charset' => 'utf8'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->set_crlf( "\r\n" );
$this->email->from($config['smtp_user']);
$this->email->to($email['user_email']);
$this->email->subject($row['tplsubject']);
$this->email->message(html_entity_decode($email_subject));
$this->email->send();
This code not working its showing error
A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465
(Unable to find the socket transport "ssl" - did you forget to enable
it when you configured PHP?)
Filename: libraries/Email.php
Line Number: 1689
I am facing the same problem with Email on a server, the solution for this problem is to change the 'protocol' from 'smtp' to 'ssmtp' and 'smtp_host' from 'ssl://smtp.gmail.com' to 'ssl://ssmtp.googlemail.com'. This thing is working fine for me.
This is not a codeigniter problem, but a php settings related problem. The answer to this question can be found here: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?
One thing to note is that in codeigniter you can use an e-mail config file, to hold all your config settings. (so you don't have to define them each time in a controller). You can do this by creating the file: application/config/email.php you can then fill this file with your settings, like this:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
$config = array(
'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
'smtp_host' => 'your_host',
'smtp_port' => your_port,
'smtp_user' => 'your_email',
'smtp_pass' => 'your_password',
'smtp_crypto' => 'security', //can be 'ssl' or 'tls' for example
'mailtype' => 'html', //plaintext 'text' mails or 'html'
'smtp_timeout' => '4', //in seconds
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
each time you load the library ($this->load->library('email');) these settings will be automatically loaded.
Also I recommend that you change your e-mail password immediately because you wrote your credentials in your question.
I have had the same issue was trying to connect with yandex smtp sever for sending email and it was showing fsockopen(): unable to connect to ssl://smtp.yandex.ru:465 using codeigniter framework. Adding $this->load->library('email'); before the email send function solved my problem.

Sending mail with SwiftMailer in Laravel 4

I am receiving a the following error:
Cannot send message without a recipient
This is while trying to send a email using swiftmailer. My code works in localhost and has all the parameters needed from sender to receiver but it throws an error saying it cannot send without recipient.
Here is my code:
public function email()
{
Mail::send('emails.auth.mail', array('token'=>'SAMPLE'), function($message){
$message = Swift_Message::newInstance();
$email = $_POST['email']; $name = $_POST['name']; $subject = $_POST['subject']; $msg = $_POST['msg'];
$message = Swift_Message::newInstance()
->setFrom(array($email => $name))
->setTo(array('name#gmail.com' => 'Name'))
->setSubject($subject)
->setBody($msg);
$transport = Swift_MailTransport::newInstance('smtp.gmail.com', 465, 'ssl');
//$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
if($result){
var_dump('worked');
}else{
var_dump('Did not send mail');
}
}
}
You can do this without adding your the SMTP information in your Mail::send() implementation.
Assuming you have not already, head over to app/config/mail.php and edit the following to suit your needs:
'host' => 'smtp.gmail.com',
'port' => 465,
'encryption' => 'ssl',
'username' => 'your_username',
'password' => 'your_password',
Then your code should be as simple as:
public function email()
{
Mail::send('emails.auth.mail', array('token'=>'SAMPLE'), function($message)
{
$message->from( Input::get('email'), Input::get('name') );
$message->to('name#gmail.com', 'Name')->subject( Input::get('subject') );
});
}
So, hopefully the issue is one of configuration. Do you have other environments setup that might be over-riding the app/config/mail.php configuration settings in your server where it's not working?
Please make sure you have configured all the necessary configuration correctly on
/app/config/mail.php. Ensure all the configuration is correct for the environment where the email is not working correctly.
If you want to use your Gmail account as an SMTP server, set the following in app/config/mail.php:
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'encryption' => 'ssl',
'username' => 'your-email#gmail.com',
'password' => 'your-password',
When switching to online server, you want to protect this file or switch provider so as not to expose your gmail credentials. Port 587 is for mailgun not gmail.

Having trouble testing php to send email verification in xampp

I have to write a log in, registration, and restricted members functionality for a site, i everything works but i cant test sending the verification email, but need too. see if it sends and test the verification link in the email.
i am running an Acer Aspire 5920,
Ubuntu 12.04,
Xampp 1.8.1,
Codeigniter 2.1.3
In answer to my own question i needed to pass infomation to configure xampp to send the email:
$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!';
}

Resources