Solved

using the perl mail function

Posted on 2004-09-06
4
854 Views
Last Modified: 2008-01-09
I have a contact form on my website and I want to use the Mail::Sendmail function. When the form is submitted I wanted a email confirmation sent to the user and one to me. So, my question is can the mail function be added twice to a script. This what I have, but it will not send both. Is this possible?


#send email acknowledgement
$mail{To} = $snailmail; #the user's email entered on the form
$mail{From} = 'tscott04@baker.edu';
$mail{Subject} = 'Gleam Klean - Message Confirmation';
$mail{Smtp} = 'http://email.baker.edu';
$mail{Mesage} = $msg;
sendmail(%mail);

#send request
$fmail{To} = 'cscott153752MI@comcast.net';
$fmail{From} = 'tscott04@baker.edu';
$fmail{Subject} = 'Comments/Questions';
$fmail{Smtp} = 'http://mail.baker.edu';
$fmail{Mesage} = $fmsg;
sendmail(%fmail);
0
Comment
Question by:reesecup999
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 11993595
Mail::Sendmail is a module not a function (important distinction).

Two problems.

1.  You are specifying a URI for the SMTP server instead of a server name.
2.  You have mis-typed 'Message'.

Here's some other comments/suggestions.

1.  You could use a BCC to send a copy to yourself and safe calling the sendmail function twice.
2.  Use error checking to see if the mail has been sent properly.

For example:

use Mail::Sendmail;

my %mail = (
   To           => $snailmail,
   Bcc          => 'cscott153752MI@comcast.net',
   From       => 'tscott04@baker.edu',
   Subject   => 'Gleam Klean - Message Confirmation',
   Message => $msg,
   Smtp       => 'email.baker.edu'
);

sendmail(%mail) or die $Mail::Sendmail::error;
   
0
 

Author Comment

by:reesecup999
ID: 11993618
Thanks for replying so fast. I just realized I left out the most important thing, which is the emails that will be sent have different information. The one to the user has a conformation message and the one sent to me is the form information. So is this possible? They both will have seperate messages.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 11993731
If they have separate information, then just do:

my %mail = (
   To           => $snailmail,
   From       => 'tscott04@baker.edu',
   Subject   => 'Gleam Klean - Message Confirmation',
   Message =>  $msg,
   Smtp       => 'email.baker.edu'
);

sendmail(%mail) or die $Mail::Sendmail::error;

my %mail = (
   To           => 'cscott153752MI@comcast.net',
   From       => 'tscott04@baker.edu',
   Subject   => 'Comments/Questions',
   Message =>  $fmsg,
   Smtp       => 'email.baker.edu'
);

sendmail(%mail) or die $Mail::Sendmail::error;
0
 

Author Comment

by:reesecup999
ID: 11993967
Thanks Tintin, this works great. It does exactly what I wanted.

0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question