Use email classes in CodeIgniter to send emails

Source: Internet
Author: User
Tags codeigniter

CodeIgniter has a powerful email class. The following is the code that uses it to send mail.

For more information on CI email class please refer to: http://codeigniter.org.cn/user_guide/libraries/email.html

File path is/application/controllers/welcome.php

<?php if (! defined (' BasePath ')) exit (' No Direct script access allowed ');            Class Welcome extends Ci_controller {public Function index () {$this->load->library (' email ');
		Load CI Email class//below set the email parameter $config [' protocol '] = ' smtp ';
		$config [' smtp_host '] = ' smtp.163.com ';
		$config [' smtp_user '] = ' fanteathy ';
		$config [' smtp_pass '] = ' Hu Jintao ';
		$config [' smtp_port '] = ' 25 ';
		$config [' charset '] = ' utf-8 ';
		$config [' wordwrap '] = TRUE;
		$config [' mailtype '] = ' html ';			
		
		$this->email->initialize ($config);
		The following settings email content $this->email->from (' fanteathy@163.com ', ' fanteathy ');
		$this->email->to (' 517081935@qq.com ');
		$this->email->subject (' email Test ');
		$this->email->message (' <font color=red>testing email class.</font> ');			$this->email->attach (' application\controllers\1.jpeg ');

		The path $this->email->send () relative to the index.php;		echo $this->email->print_debugger (); Returns a string containing the contents of the message, including the email header andEmail text.
	For debugging. }
}
After loading the email class, you need to configure the email parameters. After the configuration is complete, use the $this->email->initialize ($config) function to initialize the parameters. The contents of the message are then set, and the Last Call $this->email->send () sends the message. Note that if you add an attachment, the address of the attachment is the path to the index.php in the relative CI root directory. The results of the operation are as follows:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.