Source for file EMail.class.php
Documentation is available at EMail.class.php
include_once CLASSPATH. "RegExpConstants.inc.php";
require_once CLASSPATH. "core/Arrays.class.php";
* This class can be used to create emails of the type text or html. If you
* want you can add attachments.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2005 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* Stores the e-mail address of the recipient.
* @var string $target_email
* Stores the e-mail address of the recipient on reply.
* @var string $reply_email
* Stores the e-mail addresses of the recipients in carbon copy.
* @var array $target_email_copy_arr
* Stores the e-mail addresses of the recipients in blind carbon copy.
* @var array $target_email_blindcopy_arr
* Stores the subject of the e-mail.
* Stores the content of the e-mail.
* Stores the type of content of the e-mail. Possible values are
* "text/plain" or "text/html" for plain text e-mail or html e-email.
* @var string $content_type
* Stores the filenames of attached files.
* @var array $attachment_filename_arr
* Stores the content of the attachments.
* @var array $attachment_data_arr
* Stores the boundary for attachments.
* @var string $str_attachment_boundary
* Stores the chars to seperate header information. It is immediatly adviced
* to let it the character "\n", because some email-provider can't handle
* header information separated by "\r\n" correctly!
* @var string $str_header_separator
* @author Daniel Plücken <daniel@debakel.net>
* @param string $target_email
function EMail( $target_email )
* Sets the type of content of the e-mail. Possible values are
* "text/plain" or "text/html" for plain text e-mail or html e-email.
* @author Daniel Plücken <daniel@debakel.net>
* Returns whether the given email is valid.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $string The email to validate.
* Returns whether the given email is valid.
* The function name is a result of my bad english :P - sorry for that!
* @author Daniel Plücken <daniel@debakel.net>
* @param string $string The email to validate.
* Returns the stored email.
* @author Daniel Plücken <daniel@debakel.net>
* Adds an attachment to this email.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $filename
* Stores the email where the message should be send.
* @author Daniel Plücken <daniel@debakel.net>
* Stores the email where the message should be send on reply.
* @author Daniel Plücken <daniel@debakel.net>
* Adds an email to the array of emails where the message should be send in
* @author Daniel Plücken <daniel@debakel.net>
* Stores the emails where the message should be send in copy.
* @author Daniel Plücken <daniel@debakel.net>
* Adds an email to the array of emails where the message should be send in
* @author Daniel Plücken <daniel@debakel.net>
* Stores the emails where the message should be send in blind copy.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the generated attachment data as header information in mime
* @author Daniel Plücken <daniel@debakel.net>
$out .= "Content-Type: application/octetstream; "
$out .= "Content-Transfer-Encoding: base64"
$out .= "Content-Disposition: attachment; "
* Sends the email with values of the form to the addressee stored in
* @author Daniel Plücken <daniel@debakel.net>
* @param string $sender_email
function send( $sender_email, $subject = "", $content = "" )
"From: ".$sender_email."\r\n"
."Reply-To: ".$sender_email."\r\n"
!Arrays::is_empty( $this->target_email_copy_arr )
", ", $this->target_email_copy_arr
!Arrays::is_empty( $this->target_email_blindcopy_arr )
", ", $this->target_email_blindcopy_arr
count( $this->attachment_filename_arr ) > 0
? "MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary="
.$this->str_attachment_boundary."\r\n\r\n"
."--".$this->str_attachment_boundary."\r\n"
."Content-Type: ".$this->content_type."\r\n"
."Content-Transfer-Encoding: 8bit\r\n\r\n"
.$this->getAttachmentContent()
."--".$this->str_attachment_boundary."--"
: "Content-Type: ".$this->content_type."\r\n"
echo "--------------------------------\r\n";
echo "Sender: ".$sender_email."\r\n";
echo "--------------------------------\r\n";
echo "Receiver: ".preg_replace(
"!^.+?\b(".EMAIL.")\b.+?$!i",
"$1", $this->target_email
echo "--------------------------------\r\n";
echo "Subject: ".$subject."\r\n";
echo "--------------------------------\r\n";
echo "Content: ".$content."\r\n";
"!^.+?\b(". EMAIL. ")\b.+?$!i",
. "Content-Type: multipart/mixed; boundary="
. "Content-Transfer-Encoding: 8bit"
|