Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * CodeIgniter Email Helpers |
| 30 | * |
| 31 | * @package CodeIgniter |
| 32 | * @subpackage Helpers |
| 33 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/helpers/email_helper.html |
| 36 | */ |
| 37 | |
| 38 | // ------------------------------------------------------------------------ |
| 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | if ( ! function_exists('valid_email')) |
| 41 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Validate email address |
| 44 | * |
Timothy Warren | 6986479 | 2012-05-03 14:05:00 -0400 | [diff] [blame^] | 45 | * Updated to be more accurate to RFC822 |
| 46 | * see: http://www.iamcal.com/publish/articles/php/parsing_email/ |
| 47 | * |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 48 | * @param string |
| 49 | * @return bool |
| 50 | */ |
Timothy Warren | 6986479 | 2012-05-03 14:05:00 -0400 | [diff] [blame^] | 51 | function valid_email($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | { |
Timothy Warren | 6986479 | 2012-05-03 14:05:00 -0400 | [diff] [blame^] | 53 | $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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | // ------------------------------------------------------------------------ |
| 83 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | if ( ! function_exists('send_email')) |
| 85 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 86 | /** |
| 87 | * Send an email |
| 88 | * |
| 89 | * @param string |
| 90 | * @param string |
| 91 | * @param string |
| 92 | * @return bool |
| 93 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 94 | function send_email($recipient, $subject = 'Test email', $message = 'Hello World') |
| 95 | { |
| 96 | return mail($recipient, $subject, $message); |
| 97 | } |
| 98 | } |
| 99 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | /* End of file email_helper.php */ |
Andrey Andreev | b251864 | 2012-03-26 21:44:08 +0300 | [diff] [blame] | 101 | /* Location: ./system/helpers/email_helper.php */ |