Sending an E-mail (Code Included with post)

M

Michael

I know that in order to send an e-mail using Perl there must be a '\'
in front of the '@' symbol. For example department\@company.com. And
it works.

The problem that I am having is that we have many customers whom we
need to direct towards their own personal online order form. For some
reason when I try to place the '\' in front of the '@' symbol it does
not work.

For example (e-mail address removed). In order to send them an e-mail we need to
place the to have their email address take the form of
person\@isp.com.

However when i use the substr function the address remains the same.
substr([email protected], $where, 1) = "\@";
# attempt to insert '\' before '@'

The email address remains (e-mail address removed) even after using substr.

Can anyone help me out with this?

A more detailed coding segment is below (it's not long).


#!/usr/bin/perl -w
use CGI qw:)all);
print "Content-type: text/html\n\n";

$EmailAddress = param("textEmailAddress");
# From Text box on prev. page

print "EmailAddress is currently $EmailAddress";
# Check if email received

$where = index($EmailAddress, "@");
# Find the '@' symbol in the e-address

if ($where != -1) # If '@' symbol is in the e-address then
{
print "@ symbol found";
# Check to see if correct

substr($EmailAddress, $where, 1) = "\@";
# Insert "\" before the "@" symbol in the EmailAddress

print "EmailAddress is now $EmailAddress";
# Check the current value of EmailAddress
}
else # If '@' symbol is not in the e-address then
{
print "@ symbol not found";
# Check to see if correct

print "where equals $where";
# Check to see if correct
}

open(MAIL, "|/usr/sbin/sendmail -oi -t"); #Sending the email
print MAIL <<EOM;
From: department\@company.com
To: $EmailAddress
Subject: "Your Order Form"

Here is your order form


EOM
close(MAIL);
 
G

Gunnar Hjalmarsson

Michael said:
I know that in order to send an e-mail using Perl there must be a
'\' in front of the '@' symbol. For example
department\@company.com. And it works.

The problem that I am having is that we have many customers whom we
need to direct towards their own personal online order form. For
some reason when I try to place the '\' in front of the '@' symbol
it does not work.

You seem to have got most of it wrong, I'm afraid.

You need to escape the '@' character only in a double-quoted context
in order to prevent interpolation:

my $recemail = "you\@example.com";

or

print MAIL <<EOM;
From: me\@example.com
To: $recemail
....

but once stored in a variable, the '@' character shall normally not be
escaped.

If you do:

my $recemail = "you\@example.com";
print "$recemail\n";

it outputs:
(e-mail address removed)

You can skip the backslash all through if you assign variables using
single-quotes instead of double-quotes:

my $recemail = '(e-mail address removed)';

HTH
 
J

Jürgen Exner

Michael said:
I know that in order to send an e-mail using Perl there must be a '\'
in front of the '@' symbol.

Certainly not, why would Perl impose such an odd requirement?
Maybe you are confusing the situation with an at sign inside a double-quoted
string, which must be escaped to not be interpolated as an array?
Like in "(e-mail address removed)" where because of the double quotes Perl will try to
interpolate @bar as the array @bar?
For example department\@company.com. And it works.

I doubt it. This is most likely not the email address you mean. Or do you
really want to send the email to 'department\'
The problem that I am having is that we have many customers whom we
need to direct towards their own personal online order form. For some
reason when I try to place the '\' in front of the '@' symbol it does
not work.
[code snipped]
substr($EmailAddress, $where, 1) = "\@";
# Insert "\" before the "@" symbol in the EmailAddress

Nope, you don't. The backslash inside the double quoted string simply tells
Perl to not interpolate the array but to take the at sign literally. In
other words the "\@" denotes just one at sign without any leading backslash.

You may want to read up on "Quotes and quote-like operators" in "perldoc
perlop".

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top