Solved

using the perl mail function

Posted on 2004-09-06
4
845 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now