![]() |
Sending an E-mail (Code Included with post)
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 person@isp.com. 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(person@isp.com, $where, 1) = "\@"; # attempt to insert '\' before '@' The email address remains person@isp.com 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); |
Re: Sending an E-mail (Code Included with post)
Michael wrote:
> 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: you@example.com You can skip the backslash all through if you assign variables using single-quotes instead of double-quotes: my $recemail = 'you@example.com'; HTH -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl |
Re: Sending an E-mail (Code Included with post)
Michael wrote:
> 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 "foo@bar.com" 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 |
| All times are GMT. The time now is 02:46 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.