blob: c7b3abada9ad646daa0696942d95445a8d956c03 [file] [log] [blame]
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev8bf6bb62012-01-06 16:11:04 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter Email Helpers
30 *
31 * @package CodeIgniter
32 * @subpackage Helpers
33 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/helpers/email_helper.html
36 */
37
38// ------------------------------------------------------------------------
39
Derek Allard2067d1a2008-11-13 22:59:24 +000040if ( ! function_exists('valid_email'))
41{
Timothy Warren01b129a2012-04-27 11:36:50 -040042 /**
43 * Validate email address
44 *
Timothy Warren69864792012-05-03 14:05:00 -040045 * Updated to be more accurate to RFC822
46 * see: http://www.iamcal.com/publish/articles/php/parsing_email/
47 *
Timothy Warren01b129a2012-04-27 11:36:50 -040048 * @param string
49 * @return bool
50 */
Timothy Warren69864792012-05-03 14:05:00 -040051 function valid_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +000052 {
Timothy Warren69864792012-05-03 14:05:00 -040053 $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
54
55 $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
56
57 $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
58 '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
59
60 $quoted_pair = '\\x5c[\\x00-\\x7f]';
61
62 $domain_literal = "\\x5b({$dtext}|{$quoted_pair})*\\x5d";
63
64 $quoted_string = "\\x22({$qtext}|{$quoted_pair})*\\x22";
65
66 $domain_ref = $atom;
67
68 $sub_domain = "({$domain_ref}|{$domain_literal})";
69
70 $word = "({$atom}|{$quoted_string})";
71
72 $domain = "{$sub_domain}(\\x2e{$sub_domain})*";
73
74 $local_part = "{$word}(\\x2e{$word})*";
75
76 $addr_spec = "{$local_part}\\x40{$domain}";
77
78 return (bool) preg_match("!^{$addr_spec}$!", $email);
Derek Allard2067d1a2008-11-13 22:59:24 +000079 }
80}
81
82// ------------------------------------------------------------------------
83
Derek Allard2067d1a2008-11-13 22:59:24 +000084if ( ! function_exists('send_email'))
85{
Timothy Warren01b129a2012-04-27 11:36:50 -040086 /**
87 * Send an email
88 *
89 * @param string
90 * @param string
91 * @param string
92 * @return bool
93 */
Derek Allard2067d1a2008-11-13 22:59:24 +000094 function send_email($recipient, $subject = 'Test email', $message = 'Hello World')
95 {
96 return mail($recipient, $subject, $message);
97 }
98}
99
Derek Allard2067d1a2008-11-13 22:59:24 +0000100/* End of file email_helper.php */
Andrey Andreevb2518642012-03-26 21:44:08 +0300101/* Location: ./system/helpers/email_helper.php */