Sending an E-mail (Code Included with post)

Discussion in 'Perl' started by Michael, Sep 15, 2004.

  1. Michael

    Michael Guest

    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 . 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(, $where, 1) = "\@";
    # attempt to insert '\' before '@'

    The email address remains 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);
    Michael, Sep 15, 2004
    #1
    1. Advertising

  2. 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 can skip the backslash all through if you assign variables using
    single-quotes instead of double-quotes:

    my $recemail = '';

    HTH

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Sep 15, 2004
    #2
    1. Advertising

  3. 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 "" 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
    Jürgen Exner, Sep 15, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    55,439
  2. =?Utf-8?B?T3Bh?=

    Sending Mail via System.Net.Mail problem

    =?Utf-8?B?T3Bh?=, Jan 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,583
    sachya
    Jan 31, 2006
  3. =?ISO-8859-1?Q?Andr=E9s_Berenguer?=

    Sending e-mail with attachments with the default e-mail client

    =?ISO-8859-1?Q?Andr=E9s_Berenguer?=, Aug 29, 2003, in forum: Java
    Replies:
    0
    Views:
    504
    =?ISO-8859-1?Q?Andr=E9s_Berenguer?=
    Aug 29, 2003
  4. Replies:
    0
    Views:
    1,334
  5. Luke
    Replies:
    2
    Views:
    4,683
    Nigel Wade
    Mar 15, 2007
Loading...

Share This Page