Solved

using the perl mail function

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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

26 Experts available now in Live!

Get 1:1 Help Now