I tried to send a email to a Gmail account (both receiver and sender accounts were created by me and both allow access to less secured apps) via CodeIgniter, using the following settings (from my localhost WAMP sever):
$config['smtp_user']='my gmail address';
$config['smtp_pass']='my password';
$config['smtp_port']=465;
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['charset']='utf-8';
$config['protocol'] ='smtp';
The code snippet looks like this :
$this->email->from(my gmail address... , 'admin');
$this->email->to($reciever_email);
$this->email->subject(...);
$this->email->message(...);
$this->email->send();
But the mail does not get send (No weird error messages like fatal error etc. is displayed only the custom message I decided to show on failure is shown).
Can any one tell me why and how to get rid of this problem.
Try this instead:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'my user',
'smtp_pass' => 'my password',
'smtp_charset' => 'utf-8'
);
Related
I'm working with Codeigniter in CPanel and my code already sends a mail, but when it gets to the receiver, the hostname is shown on the sender.
I tried some answer to questions as : Change the sender name php mail instead of sitename#hostname.com but in Codeigniter, they don't work.
This is my code:
$config = Array(
'protocol' => 'ssmtp',
'smtp_host' => 'ssl://ssmtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'mail#domainiwant.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'useragent' => 'MY NAME',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('mail#domainiwant.com', 'MY NAME');
$email_to = 'receiver#gmail.com';
$this->email->to($email_to);
$this->email->message('Message testing ...');
$this->email->send();
However, as I said, when the mail gets to the receiver, they appear with the hostname and a completely different mail address like the one I put on $config
I know this only sets the envelope sender but I want to set the mail address to be mail#domainiwant.com instead of receiving the mail with somemail#host.com.ex
According to the documentation of CodeIgniter's email library available HERE, your whole problem is a simple typo.
$config['protocol'] allows mail, sendmail and smtp as values. If you don't set the variable, or use a value which is not allowed, the whole library defaults to mail which attempts to use your own server as the mail gateway (which explains why your sender address shows as username#servername)
Change the protocol from ssmtp to smtp so that you actually use the Google SMTP server you intend to use and you'll get the results you expect
I'd like to let the user edit the email account that will be sending notifications on a CodeIgniter web app. I usually use something like:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx', // hardcoded unhashed password
'mailtype' => 'html',
'charset' => 'utf8'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
But that is hardcoded and won't let the user configure or edit on admin's options. I was thinking on calling this from the database but then the email password will be exposed (not hashed) in the table, right?
Is there another way to make it configurable and secure?
Because you need to pass the raw password via SMTP, a hashed password will not work. You will need to use 2-way encryption. You can use the codeigniter encryption/decryption class for more security: http://codeigniter.com/user_guide/libraries/encryption.html
Should be as simple as:
$plain_text = 'This is a plain-text message!';
$ciphertext = $this->encryption->encrypt($plain_text);
// Outputs: This is a plain-text message!
echo $this->encryption->decrypt($ciphertext);
Additionally, asking for GMAIL passwords is rather insecure. I'd look to using an OAUTH approach, to have users approve your application: https://github.com/google/gmail-oauth2-tools
I'm trying to integrate SendGrid with my CodeIgniter application to send transactional emails. I've been able to send plain text emails, using the native email library in CodeIgniter and the SendGrid API with this code provided by SendGrid documentation:
<?php
$this->load->library('email');
$this->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.sendgrid.net',
'smtp_user' => 'sendgridusername',
'smtp_pass' => 'sendgridpassword',
'smtp_port' => 587,
'crlf' => "\r\n",
'newline' => "\r\n"
));
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
?>
In my version, I've filled in all the parameters, so this works.
What I am trying to do, but haven't been able to, is to apply a filter to the email with a template_id. I've designed a template in SendGrid and want these emails to be sent with that design. How do I tell SendGrid to apply the template?
PHP version: 7,
CodeIgniter version: 3
I'm trying to send email using codeIgniter's email library.
Below is my code
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.myserver.com',
'smtp_user' => 'xxx#myserver.com',
'smtp_pass' => '********',
'mailtype' => 'html',
'wordwrap' => false,
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#yourserver.com', 'xxx');
$this->email->subject('blah blah');
$this->email->message('a simple html message');
$this->email->to('any#validemail.com');
$this->email->send();
Code is on diffrent server & it is using different server's mail (Yes, two different domains)
For example code is on yourserver.com and it is using smtp of myserver.com
It was working fine till morning. but now i'm getting
554 SMTP synchronisation error (see attachment for full print_debugger() output, I hide some sensitive information. i can trust you guys but not all)
Thanks.
I tried very hard to get the issue, but i have not enough access to get details of error log or mail logs, So i changed my code as below and it worked
$config = Array(
'mailtype' => 'html',
'wordwrap' => false,
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#yourserver.com', 'xxx');
$this->email->subject('blah blah');
$this->email->message('a simple html message');
$this->email->to('any#validemail.com');
$this->email->send();
I would like to say thanks to #cherrysoft for his help offering. I'm posting it here so it may help someone.
thanks to all.
This isn't really a CodeIgniter problem and there could be quite a few things going on here but the first thing I would do is to make sure that the hostname on the web server is set correctly and that your mail server recognises this host. You should tail the mail.log on your mail server (if you have access to do this) whilst you are sending mail from your web server and you will get some more insight as to what is going on. When you have the mail log entries post here and we can look at the issue in more depth.
I am using this extension.
http://www.yiiframework.com/extension/smtp-mail
I would work properly. But From Email id in mail not set that i have defined in "SetFrom()" function but it takes Gmail username (myemail#gmail.com).
Below is my code for sending mail in my Controller.
$mail = Yii::app()->Smtpmail;
$mail->SetFrom("otherid",$from_name); // This id not coming in my response mail
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to, "");
config/main.php
'Smtpmail'=>array(
'class' => 'application.extensions.smtpmail.PHPMailer',
'Host' => "smtp.gmail.com",
'Username' => 'myemail#gmail.com',
'Password' => 'password',
'Mailer' => 'smtp',
'Port' => 465,
'SMTPAuth' => true,
'SMTPSecure' => 'ssl'
),
Gmail doesn't seem to allow sending the email via a different email-id if its not registered to the primary gmail account.
When logged in to the primary gmail account -> go to Account tab (top-right).
Search for Add another email address under Send mail as.
Add the new email address there. Confirm the link sent to the additional email account.
On confirmation, your account can send emails from either of the address.
Try the new email address now in $mail->SetFrom("new_gmail_id#gmail.com", $from_name); and it will work fine.
I have tried that and it works. Let us know if you have done all this already.