Hi,
I actually do mine different in my own code. This sends out a 2 part message (plain text and HTML). Its important these days to send out both plain and HTML versions, as it will help you with spam filters.
# Plugins::Emails::do_emailing_new("foo_bar_template","Some subject",$opts)
use MIME::Lite;
use MIME::Base64;
use Encode;
use Links::SiteHTML;
my ($template,$subject,$opts) = @_;
my $to = $opts->{to};
my $from = $opts->{from} || '"Andy" <andy@mysite.com>';
my $html = Links::SiteHTML::display($template, { %$opts } );
my $text = Links::SiteHTML::display("${template}_txt", { %$opts }, { compress => 0 } );
$html = decode( 'utf-8', $html );
$text = decode( 'utf-8', $text );
# print "FOO: $html \n";
use Email::MIME;
use Email::Address::XS;
use Email::Sender::Simple qw(sendmail);
use IO::All;
# multipart message
my @parts = (
Email::MIME->create(
body_str => $text,
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
),
Email::MIME->create(
body_str => $html,
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/html",
disposition => "inline",
}
)
);
if ($opts->{attach_file}) {
my $filename = (reverse split /\//, $opts->{attach_file})[0];
push @parts, Email::MIME->create(
attributes => {
filename => $filename,
content_type => "application/pdf",
encoding => "base64",
name => $filename,
},
body => io( $opts->{attach_file} )->binary->all,
)
}
my $email = Email::MIME->create(
header_str => [
From => $from,
To => [ $to ],
Subject => $subject,
],
parts => \@parts,
attributes => {
encoding => 'base64',
charset => "UTF-8",
content_type => "multipart/alternative",
disposition => "inline",
}
);
#print $email->as_string. "\n\n";
my $bcc = '';
my $bcc = 'andy@ultranerds.co.uk';
if ($bcc) {
sendmail($email,{ to => [$to, $bcc] });
} else {
sendmail($email->as_string);
}
}
Basically you create 2 templates - template_name.html and template_name_txt.html
Call with:
;
$opts contains the following variables:
to (email)
From memory, both of those can be in the format is:
I'm sure you can figure out the rest :)
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
I actually do mine different in my own code. This sends out a 2 part message (plain text and HTML). Its important these days to send out both plain and HTML versions, as it will help you with spam filters.
Code:
sub do_emailing_new { # Plugins::Emails::do_emailing_new("foo_bar_template","Some subject",$opts)
use MIME::Lite;
use MIME::Base64;
use Encode;
use Links::SiteHTML;
my ($template,$subject,$opts) = @_;
my $to = $opts->{to};
my $from = $opts->{from} || '"Andy" <andy@mysite.com>';
my $html = Links::SiteHTML::display($template, { %$opts } );
my $text = Links::SiteHTML::display("${template}_txt", { %$opts }, { compress => 0 } );
$html = decode( 'utf-8', $html );
$text = decode( 'utf-8', $text );
# print "FOO: $html \n";
use Email::MIME;
use Email::Address::XS;
use Email::Sender::Simple qw(sendmail);
use IO::All;
# multipart message
my @parts = (
Email::MIME->create(
body_str => $text,
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
),
Email::MIME->create(
body_str => $html,
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/html",
disposition => "inline",
}
)
);
if ($opts->{attach_file}) {
my $filename = (reverse split /\//, $opts->{attach_file})[0];
push @parts, Email::MIME->create(
attributes => {
filename => $filename,
content_type => "application/pdf",
encoding => "base64",
name => $filename,
},
body => io( $opts->{attach_file} )->binary->all,
)
}
my $email = Email::MIME->create(
header_str => [
From => $from,
To => [ $to ],
Subject => $subject,
],
parts => \@parts,
attributes => {
encoding => 'base64',
charset => "UTF-8",
content_type => "multipart/alternative",
disposition => "inline",
}
);
#print $email->as_string. "\n\n";
my $bcc = '';
my $bcc = 'andy@ultranerds.co.uk';
if ($bcc) {
sendmail($email,{ to => [$to, $bcc] });
} else {
sendmail($email->as_string);
}
}
Basically you create 2 templates - template_name.html and template_name_txt.html
Call with:
Code:
Plugins::Emails::do_emailing_new("foo_bar_template","Some subject",$opts)$opts contains the following variables:
Code:
from to (email)
From memory, both of those can be in the format is:
Code:
Some persons name <andy.newby@gmail.com>I'm sure you can figure out the rest :)
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!