CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Insert Variable into Subject Line using Mail::Sendmail

 



200mg
New User

May 29, 2009, 9:11 AM

Post #1 of 4 (2466 views)
Insert Variable into Subject Line using Mail::Sendmail Can't Post

Does anyone know how to insert a variable into the subject line using Mail::Sendmail?


FishMonger
Veteran / Moderator

May 29, 2009, 11:34 AM

Post #2 of 4 (2464 views)
Re: [200mg] Insert Variable into Subject Line using Mail::Sendmail [In reply to] Can't Post

Did you read the documentation for the module? It give an example that sets the subject header.

http://search.cpan.org/~mivkovic/Mail-Sendmail-0.79/Sendmail.pm


(This post was edited by FishMonger on May 29, 2009, 11:34 AM)


200mg
New User

May 29, 2009, 11:49 AM

Post #3 of 4 (2460 views)
Re: [FishMonger] Insert Variable into Subject Line using Mail::Sendmail [In reply to] Can't Post

Do you mean this?


Code
   

Subject => 'Test message',



I'm trying to get a variable into the 'Test message' part. The code below send "$var1" as the subject instead of the variable.


Code



use warnings;
use strict;
use Mail::Sendmail;



my $var1 = "Test";

print "Testing Mail::Sendmail version $Mail::Sendmail::VERSION\n";
print "Default server: $Mail::Sendmail::mailcfg{smtp}->[0]\n";
print "Default sender: $Mail::Sendmail::mailcfg{from}\n";

my %mail = (
To => 'bob_jones@harte-hanks.com',
From => 'bob_jones@harte-hanks.com',
#Bcc => 'Someone <him@there.com>, Someone else her@there.com',
# only addresses are extracted from Bcc, real names disregarded
#Cc => 'Yet someone else <xz@whatever.com>',
# Cc will appear in the header. (Bcc will not)
Subject => '$var1',
Message => '?',
'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);

my $var1 = "Test";
$mail{Smtp} = 'smtp.harte-hanks.com';
$mail{'X-custom'} = 'My custom additionnal header';
$mail{'mESSaGE : '} = "The message key looks terrible, but works.";
# cheat on the date:
$mail{Date} = Mail::Sendmail::time_to_date( time() - 86400 );

if (sendmail %mail) { print "Mail sent OK.\n" }
else { print "Error sending mail: $Mail::Sendmail::error \n" }

print "\n\$Mail::Sendmail::log says:\n", $Mail::Sendmail::log;


KevinR
Veteran


May 29, 2009, 12:16 PM

Post #4 of 4 (2459 views)
Re: [200mg] Insert Variable into Subject Line using Mail::Sendmail [In reply to] Can't Post

Evidently you don't understand what single-quotes do to a variable:


Code
Subject => '$var1',


single-quotes kill variable interpolation so $var1 is treated literally. Should be:


Code
Subject => $var1,

-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives