We show how to send mail in codeigniter in http://learneveryday.net/php/framework/codeigniter/ci_series/sending-email-in-codeigniter/ . Today we will show how to send attachment. We just need to add two line of code to send attachment.
Bellow is the code.
<?php /** * SENDS EMAIL WITH GMAIL */ class Email extends Controller { function __construct() { parent::Controller(); } function index() { $this->load->library('email'); $this->email->set_newline("\r\n"); $this->email->from('learneverydaytutorials@gmail.com', 'Arifur Rahman'); $this->email->to('learneverydayTutorials@gmail.com'); $this->email->subject('This is an email test'); $this->email->message('It is working. Great!'); $file = './attachments/Info.txt'; $this->email->attach($file); if($this->email->send()) { echo 'Your email was sent, successfully.'; } else { show_error($this->email->print_debugger()); } } } ?>
Create a folder name attachments in the same location of your application folder.
[smProductImageAdd src="http://learneveryday.net/codecanyon/adverticement/add_codecnayon_smart-social-share-php.png" alt= "Smart Social Share" href="http://codecanyon.net/item/php-smart-social-share/202558" title="Smart Social Share (Php Plugin)" description="Smart Social share is a php plugin . Which helps you to give user to share your content with social book mark site. There are 4 plugin in this package." ref="marifdu"]
Inside attachment folder we create a file Info.txt . Which we want to attached.
We run this code in our live testing server which link is http://smartwebsource.net/learneveryday/demos/CI/ci_series_3/index.php/email and then it show Your email was sent, successfully. message. After that we open our mail and see that the mail is send with attached.
Next tutorial we will learn how to make a contact form with attachment and send mail.
Download:http://sdrv.ms/15sS4Zq
Article Reproduced:http://learneveryday.net/php/framework/codeigniter/ci_series/send-email-with-attachments-in-codeigniter-series-3/comment-page-1/#comment-588
留言列表