How to get send main in my mail account using codeigniter mailer? - php

I am using codeigniter for sending mail directly..
How to get send main in my mail account using codeigniter mailer?
my Code:
$ci = get_instance();
$ci->load->library('email');
$config['useragent'] = "Codeigniter";
$config['protocol'] = "smtp";
$config['smtp_host'] = "mail.example.com";
$config['smtp_port'] = "25";
$config['smtp_user'] = "account#example.com";
$config['smtp_pass'] = "Password";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('account#example.com', 'Account');
$list = array($email);
$ci->email->to($list);
$this->email->reply_to('account#example.com', 'Account');
$ci->email->subject('Verify your Email');
$ci->email->message('Massge body contain');
$ci->email->send();
I want to get all send email in account#example.com send mail box. it is possible?

add cc or bcc your email account better bcc
$this->email->cc('account#example');
or
$this->email->bcc('account#example');

Related

Codeigniter - Sending emails using different SMTP settings

I have a system that uses different emails for different parts of the system. I've got my config setup with a No-Reply email. However, if I try and send an email using different SMTP settings, it will try and use the Email config settings rather than the array settings I've specified.
These are the settings that are in my Email config file
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'REMOVED';
$config['smtp_pass'] = 'REMOVED';
$config['smtp_port'] = '587';
$config['mailtype'] = 'html';
$config['charset'] = 'utf8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = '120';
$config['smtp_crypto'] = 'tls';
Below is the list of settings I have specified in the array (These are the settings that I want to send this particular email through Gmail rather than Office365)
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'REMOVED';
$config['smtp_pass'] = 'REMOVED';
$config['smtp_port'] = '587';
$config['mailtype'] = 'html';
$config['charset'] = 'utf8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = '120';
$config['smtp_crypto'] = 'tls';
Is there any way to send emails via different SMTP settings rather than the ones specified in the Email config file? I have tried to send this email via the Gmail settings but it always appears to try and send through the Email config settings.
SOLUTION:
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'REMOVED';
$config['smtp_pass'] = 'REMOVED';
$config['smtp_port'] = '587';
$config['mailtype'] = 'html';
$config['charset'] = 'utf8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = '120';
$config['smtp_crypto'] = 'tls';
$this->email->initialize($config);
Fixed my issue and now I am able to send an email through an Ad-Hoc Gmail account rather than the Office365 one.
You can override the configuration in the config/Email.php (office365 in your case) file with a specific one (gmail, in your case) by building the $config array in the controller and then use it to initialize the email library with:
$this->email->initialize($config);
For this to work you must initialize the library using the overriding $config before actually doing anything else that requires the class, or the default settings will be used automatically

SMTP Host Issue in China

I have an issue regarding smtp using codeigniter email library. It works fine with smtp.gmail.com but I have to use vpn in this case. I found other solutions like smtp.exmail.qq.com, smtp.mail.yahoo.com or smtp.sina.com but when you send the form typing your email in email field its being sent only with the email you provided in smtp user. Further please look at my code and screen shotenter image description here:
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to which you want to receive mails
$to_email =
'info#sample.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.exmail.qq.com';
//'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'myemail#exmail.qq.com';
$config['smtp_pass'] = 'my password';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);

Gsuite account won't send emails codeigniter

I just set up google mx records for my domain. When i use my normal gmail account, emails are sent but when I use my gsuite account, the mails are not sent. I am hosting my site on siteground. However I can receive emails from other email accounts on my gsuite account.
$this->load->library('email');
$subject = 'Subject';
$message = 'My message';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465
$config['smtp_user'] = 'info#mydomain.com';
$config['smtp_pass'] = 'my_password';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$config['validation'] = TRUE;
$this->email->initialize($config);
//send mail
$this->email->from('info#mydomain.com', 'MyDomainName');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
//echo json_encode($this->email->print_debugger());
if($this->email->send())
return true;
else
return false;
You didn't attach any error message, but since it's working for your other Gmail accounts, try checking if turning on access to "less secure apps" for this account solves this issue and report back.
https://myaccount.google.com/lesssecureapps
(Don't forget to choose the right account, if you're logged in to several ones).
I had similar problem, I had to create a App Password to work (details here: https://support.google.com/accounts/answer/185833?hl=en)
Once the App Password was created I used:
$subject = 'Your subject';
$message = 'Your body';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'your#email.com';
$config['smtp_pass'] = 'your app password';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$config['validation'] = TRUE;
$this->email->initialize($config);
//send mail
$this->email->from('from#email', 'Title');
$this->email->to('to#email.com');
$this->email->subject($subject);
$this->email->message($message);

Sender address is not valid when send email Codeigniter

I will make mail delivery system using PHP CodeIgniter. Email successfully submitted, but when I check my email, the sender mail is my smtp_user, not the real email sender.
for example: My smtp_user is a#gmail.com. When user send mail to me, sender mail is a#gmail.com, not user#gmail.com.
Here is my code in email.php :
$config['wordwrap'] = TRUE;
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "a#gmail.com";
$config['smtp_pass'] = "blablabla";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['priority'] = "1";
$config['newline'] = "\r\n";
And here is my controller :
$this->load->library('email');
$link=base_url()."verification/".$verification_code."";
$body="Thanks for joining <br> Your code verification is
<a href=".$link." target='_blank'>".$link."</a>";
$this->email->from($this->input->post('mails'), strtoupper($name));
$this->email->to('b#gmail.com');
$this->email->subject('New account registration');
$this->email->message($body);
$this->email->send());
What's wrong with my config email?
but if I using smtp_host with mandrillapp, I did'nt see the problem like above.

Codeigniter emailer not working

$this->load->library('email');
// set email data
$this->email->from($this->input->post('sender_email'), $this->input->post('sender_name'));
$this -> email -> set_mailtype("html");
$this->email->to('');
$this->email->reply_to($this->input->post('sender_email'), $this->input->post('sender_name'));
$this->email->subject('From: '.$this->input->post('sender_name'));
$this->email->message("<table><tr><td> </td><td>".$this->input->post('sender_name')."</td></tr><tr><td> </td><td>".$this->input->post('sender_email')."</td></tr><tr><td> </td><td>".$this->input->post('phone')."</td></tr><tr><td>Message: </td><td>".$this->input->post('message')."</td></tr></table>");
$this->email->send();
// create a view named "succes_view" and load it at the end
redirect('contact?email_succ=1');
exit();
This is the code I'm using to send email from a form in CI and it works only when I use SMTP login along with this.
$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'] = 'myemail#example.com';
$config['smtp_pass'] = 'emailpassword';
$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);
Having this code right after loading the library solves the issue. But what's wrong with the default code that has been working all this time but suddenly stopped?
UPDATE: adding just this line $this->email->initialize($config); solves the issue, But why?.
Try the following code.
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$this->email->message = "Your Message";
$this->email->subject("Message Subject");
$this->email->from("user#gmail.com");
$this->email->to("admin#gmail.com");
$this->email->send();

Categories