?
Solved

using the perl mail function

Posted on 2004-09-06
4
Medium Priority
?
892 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans
Suggested Courses

800 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