Results 1 to 10 of 10
-
28th Nov 2009, 07:56 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.com[PHP] E-mailer (Attachment Support) [/PHP]
Heres a nice email class i createed that you can use in your projects and you can also add attachments to the email....
Key-Features:
- Simple OOP
- Plain-Text OR Html Formatted
- Use both Plain-Text and Html to help with unsupported clients
- Able to add attachments of any sort
- Based on PHP-Mail
- Multiple Recipients in one batch
- Built for "Php Newbies"
Available on PhpClasses
Some Usage Smaples
Simple Plain text
PHP Code:<?php
//Include the emailer class
include 'Emailer.class.php';
//Load the Emailer class into a variable
$Emailer = new Emailer;
//Setup where and where from the message is being sent.
$Emailer->set_to("some_email@some_domain.tld");
$Emailer->set_from("admin@localhost");
$Emailer->set_sender("me@domain.com");
//Afdd some message stuff
$Emailer->set_subject("This is a plain-text email");
$Emailer->set_text("Hello World!");
$Emailer->send();
?>
PHP Code:<?php
//Include the emailer class
include 'Emailer.class.php';
//Load the Emailer class into a variable
$Emailer = new Emailer;
//Setup where and where from the message is being sent.
$Emailer->set_to("some_email@some_domain.tld");
$Emailer->set_from("admin@localhost");
$Emailer->set_sender("me@domain.com");
//Add some message stuff
$Emailer->set_subject("This is a html formatted email");
/*Set the text if the end-user does not have the correct software to view html*/
$Emailer->set_text("Hello World! (Non html version)");
$Emailer->set_html("<strong>Hello World!</strong> (html Version)");
//html will show if supported otherwise they will be sent a nice plain-text version
$Emailer->send();
?>
PHP Code:<?php
//Include the emailer class
include 'Emailer.class.php';
//Load the Emailer class into a variable
$Emailer = new Emailer;
//Setup where and where from the message is being sent.
$Emailer->set_to("some_email@some_domain.tld");
$Emailer->set_from("admin@localhost");
$Emailer->set_sender("me@domain.com");
//Afdd some message percifics
$Emailer->set_subject("This is a html formatted email with files");
/*Set the text if the end-user does not have the correct software to view html*/
$Emailer->set_html("Here's your files");
//Add some files
$Emailer->add_attachments(
array(
"test/account_details.txt",
"test/your_avater.png",
"test/some_sample_source.php",
"test/some_random.ext"
/*Add as many as you wish but try not overload the message size by sending 100MB download lol*/
)
);
$Emailer->send();
?>
PHP Code:<?php
class Emailer{
/*protected Methods*/
protected
$to,
$from,
$sender,
$subject,
$text,
$html;
/*Attachments Holder*/
protected $attachments = array();
/*Public Variables*/
public $charset = 'utf-8';
public $eol = "\r\n";
/*Constructor*/
public function __construct(){
/*null*/
}
//Setters
public function set_to($to){$this->to = $to;}
public function set_from($from){$this->from = $from;}
public function set_sender($sender){$this->sender = $sender;}
public function set_subject($subject){$this->subject = $subject;}
public function set_text($text){$this->text = $text;}
public function set_html($html){$this->html = $html;}
//Adders
public function add_attachments($attachment){
//Check if input is an array or string
if(!is_array($attachment)){$attachment = array($attachment);}
$this->attachments = array_merge($this->attachments, $attachment);
}
//Send mail
public function send(){
//Check Variables are set
if(empty($this->to)){
trigger_error('To required (Use set_to() to set this)!',E_USER_ERROR);
}
if(empty($this->from)) {
trigger_error('From required! (Use set_from() to set this)',E_USER_ERROR);
}
if(empty($this->sender)){
trigger_error('Sender required! (Use set_sender() to set this)',E_USER_ERROR);
}
if(empty($this->subject)){
trigger_error('Subject required! (Use set_subject() to set this)',E_USER_ERROR);
}
if((empty($this->text)) && (empty($this->html))){
trigger_error('Message required! (Use set_text() OR set_html() to fix this)',E_USER_ERROR);
}
//Check for multiple emails within the the send to var.
$this->to = (is_array($this->to) ? implode(',', $this->to) : $this->to);
//Start compiling the email
$this->boundary = '----=_NextPart_' . md5(rand());
$this->headers = '';
$this->message = '';
//Do top headers
$this->headers .= 'From: ' . $this->sender . '<' . $this->from . '>' . $this->eol;
$this->headers .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $this->eol;
$this->headers .= 'Return-Path: ' . $this->from . $this->eol;
$this->headers .= 'X-Mailer: PHP/' . phpversion() . $this->eol;
$this->headers .= 'MIME-Version: 1.0' . $this->eol;
$this->headers .= 'Content-Type: multipart/mixed; boundary="' . $this->boundary . '"' . $this->eol;
if(empty($this->html)){
//Text Only
$this->message = '--' . $this->boundary . $this->eol;
$this->message .= 'Content-Type: text/plain; charset="' . $this->charset . '"' . $this->eol;
$this->message .= 'Content-Transfer-Encoding: base64' . $this->eol . $this->eol;
$this->message .= chunk_split(base64_encode($this->text));
}else{
$this->message = '--' . $this->boundary . $this->eol;
$this->message .= 'Content-Type: multipart/alternative; boundary="' . $this->boundary . '_alt"' . $this->eol . $this->eol;
$this->message .= '--' . $this->boundary . '_alt' . $this->eol;
$this->message .= 'Content-Type: text/plain; charset="' . $this->charset . '"' . $this->eol;
$this->message .= 'Content-Transfer-Encoding: base64' . $this->eol;
if(!empty($this->text)){
$this->message .= chunk_split(base64_encode($this->text));
}else{
$this->message .= chunk_split(base64_encode('This E-Mail contains HTML but your email client does not support HTML'));
}
$this->message .= '--' . $this->boundary . '_alt' . $this->eol;
$this->message .= 'Content-Type: text/html; charset="' . $this->charset . '"' . $this->eol;
$this->message .= 'Content-Transfer-Encoding: base64' . $this->eol . $this->eol;
$this->message .= chunk_split(base64_encode($this->html));
$this->message .= '--' . $this->boundary . '_alt--' . $this->eol;
}
//Lets do some attachments
foreach ($this->attachments as $attachment){
$filename = basename($attachment);
if(!file_exists($attachment)){
trigger_error("Attachment <{$filename}> does not exists!",E_USER_ERROR);
}
//Continue to Fopen->Fread->Fclose
$handle = fopen($attachment, 'r');
$content = fread($handle, filesize($attachment));
fclose($handle);
$this->message .= '--' . $this->boundary . $this->eol;
$this->message .= 'Content-Type: application/octetstream' . $this->eol;
$this->message .= 'Content-Transfer-Encoding: base64' . $this->eol;
$this->message .= 'Content-Disposition: attachment; filename="' . $filename . '"' . $this->eol;
$this->message .= 'Content-ID: <' . $filename . '>' . $this->eol . $this->eol;
$this->message .= chunk_split(base64_encode($content));
}
//Now lets send the mail via PHPMAIL
ini_set('sendmail_from', $this->from);
mail($this->to, $this->subject, $this->message, $this->headers);
/*
*** SMTP sender may be created here depending on how many users wish for it.
*/
}
}
?>litewarez Reviewed by litewarez on . [PHP] E-mailer (Attachment Support) [/PHP] Heres a nice email class i createed that you can use in your projects and you can also add attachments to the email.... Key-Features: Simple OOP Plain-Text OR Html Formatted Use both Plain-Text and Html to help with unsupported clients Able to add attachments of any sort Based on PHP-Mail Multiple Recipients in one batch Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 05:41 AM #2Too busy :|Website's:
L337Fx.com BeastieBay.netWOW
Fantastic Nice job litewarez
-
29th Nov 2009, 05:44 AM #3Member
yea another A++ tutorial/script
-
29th Nov 2009, 09:07 AM #4OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comthanks, i just thought that alot of users have issues with headers etc with php's mail() function so thought id make a class to make everything simpler for you all... alsop this is released under GPL no and will be available on phpclasses soon
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 10:13 AM #5(╯?□?)╯︵ ┻━┻Website's:
Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.compretty useful class but try to use isset() or empty() in your if statements rather than checking if it is false (!$). Empty is probably best.
Reason being, you can have a var set to a value which is seen as false.Projects:
WCDDL - The Professional DDL Script
Top Secret Project: In Development - ZOMG
ImgTrack - Never Have Dead Images Again!
-
29th Nov 2009, 10:18 AM #6OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comYea i dont know why i did not do that in the beginning :/ prob because i thought they would be set with the protected declaration.. thanks anyhow, ill use empty
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 10:29 AM #7(╯?□?)╯︵ ┻━┻Website's:
Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.comYeah, I was going to suggest isset() but I remembered empty() returns true for declared vars without values (e.g. protected $var; ).
So thats best for this situation.Projects:
WCDDL - The Professional DDL Script
Top Secret Project: In Development - ZOMG
ImgTrack - Never Have Dead Images Again!
-
29th Nov 2009, 12:01 PM #8OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comyea i would have used isset but then the vars are already declared sooo empty is more appropriate thanks tho bud
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 12:31 PM #9Member
Neat, clean code, I like it.
One thing, some hosts have ini_set() disabled (I know I do on most shared hosting machines), perhaps specify the sender in an additional parameter to mail()....
-
29th Nov 2009, 01:32 PM #10OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comTo be honest i cant believe i missed that parameter lol... may change it thanks voltage
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Image Attachment Permission ?
By Noob in forum vBulletinReplies: 10Last Post: 13th Jan 2012, 11:01 AM -
redirect to home page when download attachment
By bluedevil in forum vBulletinReplies: 3Last Post: 20th Aug 2011, 07:37 AM -
Attachment problem!!!!!!!
By Noob in forum vBulletinReplies: 2Last Post: 10th Jul 2011, 03:24 PM -
Attachment file size
By Spooky in forum IP.BoardReplies: 4Last Post: 13th Sep 2010, 03:48 PM -
[TUT]Setting / Adjusting Attachment Limits
By Lease in forum IP.BoardReplies: 0Last Post: 13th Jan 2008, 01:23 AM
themaManager - edit and manage...
Version 4.04 released. Open older version (or...