Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am wanting to send an email with the Mail::Sendmail module using a dynamic $variables as mail parameters.

I can get this to work

my %mail = ( From => 'tester@hotmail.com\n', To => 'to.test.com', Subject => 'Static Email', 'content-type' => 'text/html; charset="iso +-8859-1"', );

When i attempt to use the following, it creates errors. How can I modify the script to accept variables

my %mail = ( From => 'tester@hotmail.com\n', To => $email, Subject => $subject, 'content-type' => 'text/html; charset="iso-8859-1"', );

Can someone tell me why this won't work and what needs to be change
Thankyou

Edited by Chady -- code tags.

Replies are listed 'Best First'.
Re: Mail::Sendmail variables
by pg (Canon) on Nov 07, 2004 at 03:56 UTC

    Most likely has something to do with things like @ in email address. For example, this works:

    use Mail::Sendmail; my $me = "me\@aicompro.com"; my %mail = ( To => $me, From => $me, Message => "This is a very short message", smtp => 'mail.aicompro.com' ); sendmail(%mail) or die $Mail::Sendmail::error;

    This does not:

    use Mail::Sendmail; my $me = "me@aicompro.com"; my %mail = ( To => $me, From => $me, Message => "This is a very short message", smtp => 'mail.aicompro.com' ); sendmail(%mail) or die $Mail::Sendmail::error;
Re: Mail::Sendmail variables
by saberworks (Curate) on Nov 07, 2004 at 09:11 UTC
    First off, you should use CODE tags around your code. Second, you really should post the exact error messages you're getting. Third, you're putting a \n inside a single-quoted string, which will not turn that into a newline, which you're probably expecting. You should either use double quotes, or even better, get rid of the \n altogether in the email address (mail::sendmail will take care of that for you). There are possibly other errors, we can help more if you post the error message you're getting.
Re: Mail::Sendmail variables
by Ashford (Initiate) on Nov 09, 2004 at 00:14 UTC
    Did you set the value of the variables in your script?

    my ($email, $subject) = @_;

    my $subject = shift;
    my $email = shift;

Re: Mail::Sendmail variables
by daveinthesky (Beadle) on Nov 10, 2004 at 21:57 UTC
    Your email address string has a "\n" in it. Try it without that.
    David