Solved

email function in CGI

Posted on 1998-09-02
19
263 Views
Last Modified: 2013-12-25
My question is to write a email function cgi program. One submit... it wake up our email program such as outlook express and send it out.
0
Comment
Question by:ht055
[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
19 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 1828439
You don't need CGI for that, HTML will do fine:

<form action="mailto:anyone@anywhere.com">
<input type="submit">
</form>
0
 
LVL 1

Expert Comment

by:Patricia080698
ID: 1828440
Are you using ASP (Active server Pages) ?
0
 

Author Comment

by:ht055
ID: 1828441
No...I'm not run on ASP.

I think I didn't declare very clearly. Sorry!

What I want is :

A mail list in a page. All of them have a check box. If I want send a mail to two particular person such as friend1 and friend2. So I check the check box and then click on submit button. Then it wake up my mail program such as outlook express and they are email address would be put in the 'to' recipient

For instant:

checkbox1 Friend1(included the email address)
checkbox2 Friend2(included the email address)
checkbox3 Friend3(included the email address)
checkbox4 Friend4(included the email address)

If I want to send a mail to friend1 and friend2, then I click on the checkbox1 and checkbox2. Then click on submit button...it wake a mail program and put the email address of them in 'to' recipient.

Thanks.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 4

Accepted Solution

by:
rafistern earned 50 total points
ID: 1828442
The basic idea is what sybe said. However the details are like this:

<script>
function sendmail(){
  var recipients="";
  for(i=0;i<document.mailForm.length;i++){
    if(document.mailForm.elements[i].checked){
      recipients=recipients+";"+document.mailForm.elements[i].name;
    }
  }
 document.location.href="mailto:x@y;a@b";
}
</script>
<form name=mailForm>
<input type=checkbox name="friend1@xyz">friend1
<input type=checkbox name="friend2@abc">friend2
<input type=checkbox name="friend3@pqr">friend3
<input type=button onclick="sendmail();">
</form>

This should open your mail program with a multiple sender in the to field.

(I am not sure whether the delimitter between the recipient names should be ";" or ",". Try it and see.)
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828443
There is a mistake in the answer.
 document.location.href="mailto:x@y;a@b";
should read
 document.location.href="mailto:"+recipients;

Sorry,
Rafi

0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828444
This is real embarrassing. I just found another bug in my own answer. Well at least I found it and not someone else!

The script should be:

function sendmail(){
  var recipients="";
  for(i=0;i<document.mailForm.length;i++){
    if(document.mailForm.elements[i].checked){
      recipients=recipients+document.mailForm.elements[i].name+";";
    }
  }
 document.location.href="mailto"+recipients;
}
</script>

Rafi
0
 

Author Comment

by:ht055
ID: 1828445
Thanks for above solution.

Is there above code running on the Javascipt and no need write in cgi code???


0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828446
Yes you are right. This is all client-side JavaScript.
0
 

Author Comment

by:ht055
ID: 1828447
I follow the below code and found an error when sending a mail. There is the recipient always end with ';'. For eaxample, if i send to friend1(abc@mail.com) i.e in 'to' fields look like abc@mail.com;

so the mail can't reach to abc@mail.com because of ';'.

please let me know i have a solution for it.

thanks.

function sendmail(){
  var recipients="";
  for(i=0;i<document.mailForm.length;i++){
    if(document.mailForm.elements[i].checked){
      recipients=recipients+document.mailForm.elements[i].name+";";
    }
  }
 document.location.href="mailto:"+recipients;
}
// --></script> </p>
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828448
add in the line

recipients=recipients.substring(0,recipients.length-2);

This should get rid of the final character.
0
 

Author Comment

by:ht055
ID: 1828449
It is only work if there is only have one recipient.

If there is more than one recipient... it doesn't work. It look like this :

friend2@abfriend3@pq

it combined the mail address person one + mail address person two.

please give me some clue.

thanks you very much.
0
 

Author Comment

by:ht055
ID: 1828450
Hi,

Trouble you again.

How to add the error message if all the check box is uncheck??? which means no recipient has been select.
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828451
The multiple recipients works on my mail program.

Try
recipients=recipients+document.mailForm.elements[i].name+",";
i.e. with "," not ";"

To check for no checkboxes checked do:

function sendmail(){
  var recipients="";
  var flag=false;
  for(i=0;i<document.mailForm.length;i++){
    if(document.mailForm.elements[i].checked){
      recipients=recipients+document.mailForm.elements[i].name+";";
      flag=true;
    }
  }
  if(flag){
   document.location.href="mailto:"+recipients;
  }
}

then it will only mail if at least one was checked.
0
 

Author Comment

by:ht055
ID: 1828452
Hi Rafistern,

Thank you very much. You are so wonderful!
0
 

Author Comment

by:ht055
ID: 1828453
Hi,

Asking one more question.

Add one more checkbox that when the check box is check(first time click), it select all the checkbox(all check box are check). So it would put all the email address in the 'to' field. so not need to click one by one check box if want to send a mail to all recipients.

Select click on check box.... it would uncheck the checkbox. So...there is no recipient in 'to' field.

Thanks.




0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828454
function sendmail(){
  var recipients="";
  var flag=false;
  for(i=0;i<document.mailForm.length;i++){
    if(document.mailForm.elements[i].checked){
      recipients=recipients+document.mailForm.elements[i].name+";";
      flag=true;
    }
  }
  if(flag){
   document.location.href="mailto:"+recipients;
  }
  else{
    alert("You have not chosen any recipients!");
  }
}


I think that I have given you enough help now for 50 points. More questions=more points.
0
 

Author Comment

by:ht055
ID: 1828455
How many points you want?
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1828456
If you have more questions, then submit them as a new question.
0
 

Author Comment

by:ht055
ID: 1828457
Thank for your suggestion. Your are so lovely!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.php tree directory? 5 89
Awk : two files math 8 29
Automate PC's, Laptop to correct OU 4 45
New-MoveRequest Exchange 2010 Powershell 1 42
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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