I am going nuts soon!
I am trying to send an email to a newly registered user of my webpage with an membership activation link. Here are some parts from my code.
#this is my sub for sending the email
sub sendMail{
# application object
my $self = shift;
# get arguments
my ($to, $from, $subject, $text) = @_;
open (MAIL, "|/usr/lib/sendmail -t -oi")
or die("Can not find sendmail: $!");
print MAIL <<_MAIL_;
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
To: $to
From: $from
Cc:
Subject: $subject
$text
_MAIL_
close MAIL;
}
I am calling the sendMail sub from another sub with the following data:
my $from = "noreply\@xxxxxx.com";
my $subject = "Membership";
my $link = "http://www.xxxxxx.com/xxxxxx/index.cgi?rm=activate&id=$act
+ivate_code&email=$email";
my $text = "<html><head><title></title></head><body><a href=\"$link\">
+$link</a></body></html>";
$self->sendMail($email, $from, $subject, $text);
There can be some smaller syntax error in the above code because I took it out from the bigger picture.
I am using Data::GUID for my $activate_code for example: 956F8CE6-BA7D-11DA-A132-94F4820E4FA7 and the email to the user comes from a mySQL DB.
I've tried to encode the link with the following sub:
sub URLEncode {
my $theURL = $_[0];
$theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
return $theURL;
}
I dont know where to start with my questions?
First of all should I send the email as text/plain or text/html?
Can I somehow make sure this email can be read from both commercial email services and for example: outlook?
Do I have to encode the link?
I pretty much trialed and errored every possible combination encoding/decoding to different email addresses. If someone could point me in the right direction, is there any modules I can use or ready made scripts for this?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.