CodeIgniter e-Mail based on email class _php Example

Source: Internet
Author: User
Tags codeigniter

This article gives an example of CodeIgniter email based on email class. Share to everyone for your reference, specific as follows:

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
    The following 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 (); Return contains message contentsstrings, including email headers and email text.
  For debugging.

 }
}

After loading the email class, you need to configure the email parameters. Use after configuration is complete

$this->email->initialize ($config)

To initialize the parameters. Then set the contents of the message, and finally call

$this->email->send ()

Send 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:

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.