Link to home
Start Free TrialLog in
Avatar of reesecup999
reesecup999

asked on

using the perl mail function

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);
Avatar of Tintin
Tintin

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;
   
Avatar of reesecup999

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Tintin, this works great. It does exactly what I wanted.