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.
Related
I have configured the email function in my Codeigniter application with the following...
$config = [
'protocol' => 'smtp',
'smtp_host' => 'smtp.xxxxx.com',
'smtp_user' => 'xxxxx',
'smtp_pass' => 'xxxxx',
'newline' => "\r\n",
'smtp_port' => 587,
'mailtype' => 'html',
'charset' => 'UTF-8'
];
And sending using...
$sub = 'KONERU Created Sucessfully';
$msg = '<p><a href="koneru.com" >KONERU</a> - Has been Created Sucessfully!</p>';
$msg .= '<br><br><br><p>This mail Generated by computer.<br>Please Don\'t replay to this mail.</p>';
$this->load->library('email', $config);
$this->email->from('xxxxxxxxx','xxxxxxx xxxxxx');
$this->email->to('xxxxxxxxxxxxxx');
$this->email->subject($sub);
$this->email->message($msg);
$this->email->send();
Am able to send an email, but I didn't see HTML format properly on Outlook inbox, I am seeing something like this...
KONERU - Has been Created Su=essfully!
This mail Generated by c=mputer.
Please Don't replay to this mail.
I don't know why, I am seeing some '=' in-between text, I tried with different charset like UTF-8, iso-8859-1 but nothing seems to work.
If I use mailtype = 'text', then if I tried to send a plain text without HTML tags, I didn't see any '=' in between text.
Yes, finally! by adding...
$this->email->set_crlf( "\r\n" );
to configuration, solved my problem.
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';
}
I am doing a project using Codeigniter (Mobile Website). I want users to receive mails such as registration, forgot password, newsletters etc. Currently what I am doing is like :
function sendEmail($email) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'user#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('user#gmail.com', 'user');
$this->email->to($email);
$this->email->subject('Thank You for Registering');
$this->email->message('Thank You for Registering .');
if($this->email->send()){
echo "Success";
}
else {
echo "failed";
}
}
This works well. But is this the right way of doing things when you want to send mails of 2-3 types ? Please help me on this.
I would recommend to create email.php file in ./application/config folder and put your config array in that file. So when you change your email settings it will reflect in entire application. For more details visit Email class in codeigniter.
I would recommend not using Gmail smtp for a web application in production. Instead use premium (paid) services like www.mailgin.com where you can also use your own domain for sending, etc.
Or set up your own email server.
I would also recommend using a framework for sending the emails, for example www.swiftmailer.org
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);
I use CI library for sending HTML email through smtp. When i try to send from my computer, it send right HTML. but when i send it from server, why i get HTML tag. not formatted as html ? I already set 'mailtype' to 'html'.
I wonder why it work at my local but not at server. Is there any configuration in php ? or i should send email header or something?
public function index()
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx',
'smtp_pass' => 'xxxx',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->load->library('email', $this->config->item('email'));
$this->email->set_newline("\r\n");
$this->email->from('xxxx', 'xxxx');
$this->email->to("xxxx");
$this->email->subject('Test Email');
$body = $this->load->view('welcome_message',null,TRUE);
$this->email->message($body);
if (!$this->email->send()){
echo 'fail to load email';
}
else {
echo 'success to send email';
}
}
Setting config options doesn't work unless you initialize them. Add this after your $config array:
$this->email->initialize($config);
Based on what I think you're trying to do:
$this->load->library('email', $this->config->item('email'));
should be
$this->load->library('email', $config);
Try and let us know.