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

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

Related

login registration and verify email (gmail) 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.

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

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

send email with attachment in CodeIgniter

Pdf attachment through email in CodeIgniter Mysource code here
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('test#gmail.com');
$this->email->to($useremail);
$this->email->cc('');
$this->email->subject('pdf');
$this->email->message($message);
$this->email->attach('public_html/invoicepdf/171.pdf');
$mailsucc = $this->email->send();
I tried with this but didnt work
$this->email->attach('public_html/invoicepdf/171.pdf');
And i also replace path with URL.
You can send attach file using
$this->email->attach($atch);
method in codeigniter. in this below code i'm sending mail using SMTP with
Attached File.
its Working perfectly.
You only need to specify base_url to define attachment file path
Controller
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'yourmail#gmail.com', // change it to yours
'smtp_pass' => 'mypasswords', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
// Defined Attachment file using variable
$atch=base_url().'html/images/logo.png';
$this->load->library('email', $email_config);
$this->email->set_newline("\r\n");
$this->email->from('test#gmail.com', 'Rudra'); // email From
$this->email->to('mailtosend#gmail.com'); // eMail to send
$this->email->subject('Mail with Attachment'); // Subject
$this->email->message("This is mail with Attachment file using CodeIgniter."); // Message
$this->email->attach($atch); // Attachment file defined using variable
$maill=$this->email->send(); // send mail
if($maill>0)
{
echo 'Email sent.'; // success
}
else
{
show_error($this->email->print_debugger());
}

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.

Resources