Codeigniter 3: Email not sending via third party [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
my webiste is hosted in infinityfree and I tried send emails and I'm not receiving any. This is the code that I used
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$result = $this->email->send();
Do I have to setup something in google or in the control panel of my website? thank you

This is the simplest way to send a email in codeigniter
$this->load->library('email');
$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();
By using this code, you can check the mail functionality. You can also follow the codeigniter email class
Codeigniter email class

Try this
First, load the library
$this->load->library('email');
$this->email->from('test#abc.com', 'Sender Name');
$this->email->to('to#gmail.com');
$this->email->subject('Sample');
$this->email->message('Email testing');
Use condition to check if email send or not
if($this->email->send()){
echo 'Scuuess';
}else{
echo 'Fail';
}

Related

Sending Mail Using Gmail In Codeigniter

I will try to send mail using gmail in codeigniter. I write code as given bellow. When i upload it on c panel it will work properly for 2 days but after that it stop working.
//Load email library
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxx',
'smtp_pass' => 'xxxxxx',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype('html');
$this->email->set_newline("\r\n");
//Email content
$htmlContent = '<h1>MY WEBSITE</h1>';
$htmlContent .= '<p>OTP For Reset Your Password.</p>';
$this->email->to($uemail);
$this->email->from('xxxxxxxx','MyWebsite');
$this->email->subject('MESSAGE');
$this->email->message($htmlContent);
//Send email
$this->email->send();
I experienced the same thing where the email was not sent and there was no error, it turned out that when I checked my Gmail account it wasn't always on the Primary tab (make sure it wasn't in the Spam folder either). Sent but in the Promotions tab.

SMTP success but the email is not delivered

I'm a newbie to CodeIgntier. I'm trying to setup SMTP on CodeIgniter. I receive a success message on page but email is not delivered. Can somebody help me?
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->from('xxx#gmail.com', 'Admin Team');
$sendTo = $this->input->post('email');
$message= 'Hello';
$this->email->to($sendTo);
$this->email->subject('Verification Email');
$this->email->message($message);
if($this->email->send()){
echo "Success";
}
You have mentioned xxx#gmail.com. In google there is Security protection call 2-Step Verification. Make sure its there,If there remove it and try
There is no fault in your code. . To remove it check this link
your code seems ok, make sure your server has openssl extension up and running , and check your firewall for the used smtp port (465 in your case). I would also recommend you using the third party library phpmailer from https://github.com/ivantcholakov/codeigniter-phpmailer whic (mostly for sending html in your message and links )
cheers!

Sending mail using dompdf [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
DOMPDF - attach created PDF to email
I want to send an email instantaneously once PDF is generated.
Have ver. dompdf_0-6-0_beta3 of DOMPDF and php ver 5.2 . Able to generate PDF as required. But can anyone please help me as how to send mail with generated pdf as attachment.
This is what i did in my application please go through it and if you have any doubts let me know.
I am assuming you can able to send mail from your application.
$pdf = $dompdf->output();
$file_location is the path where you saved your pdf file in your local host.
file_put_contents($file_location,$pdf);
Now call your mail function like this.
sendMail($from,$to,$subject,$message,$file_location);
function sendMail()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com', // change it to yours
'smtp_pass' => 'xxx', // 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->attach($file_location);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Now write a mail function like i mentioned in the comments.

Sending mail to multiple recipients with sendgrid and codeigniter

I recently signed up for SendGrid and took a look at their integration into CodeIgniter.
They recommend doing the following to send mail out:
$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();
This seems like a nice solution for sending out emails to single individuals but what if I have an email that I want to send to a whole bunch of people? Is it possible to send either the "to" or the "bcc" in as an array?
Is there a different integration method preferred for using SendGrid with CI?
Thanks!
You can use it in the normal way. You can pass an array of email addresses or a comma separated string of email addresses.
Like
$list = array('one#example.com', 'two#example.com', 'three#example.com');
// or
//$list = 'one#example.com, two#example.com, three#example.com';
$this->email->to($list);
// or
//$this->email->cc($list);
// or
//$this->email->bcc($list);

codeigniter Mail to going to Spam any solution [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you make sure email you send programmatically is not automatically marked as spam?
I am sending using codeigniter email library. i am usimg SMTP PROTOCOL.
$this->load->library('email');
$config = array(
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_user' => 'xxxx#gmail.com',
'smtp_pass' => 'xxxx',
'smtp_port' => '465',
'smtp_host' => 'ssl://smtp.gmail.com',
'mail_path' => 'ssl://smtp.gmail.com'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from("xxxx#gmail.com","xxxx");
$message = "Dear Admin,<br /><br />";
$this->email->subject('Notification');
$this->email->message($message);
$this->email->send();
Email is sending perfectly but its going to spam. I want to inbox
That example is triggering gmail's spam filter. Provide some actual content with wording that looks important. Or at least not like spam.
$message = "Dear firstname lastname,<br /><br />As you have chosen on the setup page, you are receiving this message to indicate that the requested threshold has been reached.";
$this->email->subject('Notification for recurring bill payment');
$this->email->message($message);

Categories