ht055
asked on
email function in CGI
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.
Are you using ASP (Active server Pages) ?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is a mistake in the answer.
document.location.href="ma ilto:x@y;a @b";
should read
document.location.href="ma ilto:"+rec ipients;
Sorry,
Rafi
document.location.href="ma
should read
document.location.href="ma
Sorry,
Rafi
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.mailFor m.length;i ++){
if(document.mailForm.eleme nts[i].che cked){
recipients=recipients+docu ment.mailF orm.elemen ts[i].name +";";
}
}
document.location.href="ma ilto"+reci pients;
}
</script>
Rafi
The script should be:
function sendmail(){
var recipients="";
for(i=0;i<document.mailFor
if(document.mailForm.eleme
recipients=recipients+docu
}
}
document.location.href="ma
}
</script>
Rafi
ASKER
Thanks for above solution.
Is there above code running on the Javascipt and no need write in cgi code???
Is there above code running on the Javascipt and no need write in cgi code???
Yes you are right. This is all client-side JavaScript.
ASKER
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.mailFor m.length;i ++){
if(document.mailForm.eleme nts[i].che cked){
recipients=recipients+docu ment.mailF orm.elemen ts[i].name +";";
}
}
document.location.href="ma ilto:"+rec ipients;
}
// --></script> </p>
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.mailFor
if(document.mailForm.eleme
recipients=recipients+docu
}
}
document.location.href="ma
}
// --></script> </p>
add in the line
recipients=recipients.subs tring(0,re cipients.l ength-2);
This should get rid of the final character.
recipients=recipients.subs
This should get rid of the final character.
ASKER
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.
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.
ASKER
Hi,
Trouble you again.
How to add the error message if all the check box is uncheck??? which means no recipient has been select.
Trouble you again.
How to add the error message if all the check box is uncheck??? which means no recipient has been select.
The multiple recipients works on my mail program.
Try
recipients=recipients+docu ment.mailF orm.elemen ts[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.mailFor m.length;i ++){
if(document.mailForm.eleme nts[i].che cked){
recipients=recipients+docu ment.mailF orm.elemen ts[i].name +";";
flag=true;
}
}
if(flag){
document.location.href="ma ilto:"+rec ipients;
}
}
then it will only mail if at least one was checked.
Try
recipients=recipients+docu
i.e. with "," not ";"
To check for no checkboxes checked do:
function sendmail(){
var recipients="";
var flag=false;
for(i=0;i<document.mailFor
if(document.mailForm.eleme
recipients=recipients+docu
flag=true;
}
}
if(flag){
document.location.href="ma
}
}
then it will only mail if at least one was checked.
ASKER
Hi Rafistern,
Thank you very much. You are so wonderful!
Thank you very much. You are so wonderful!
ASKER
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.
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.
function sendmail(){
var recipients="";
var flag=false;
for(i=0;i<document.mailFor m.length;i ++){
if(document.mailForm.eleme nts[i].che cked){
recipients=recipients+docu ment.mailF orm.elemen ts[i].name +";";
flag=true;
}
}
if(flag){
document.location.href="ma ilto:"+rec ipients;
}
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.
var recipients="";
var flag=false;
for(i=0;i<document.mailFor
if(document.mailForm.eleme
recipients=recipients+docu
flag=true;
}
}
if(flag){
document.location.href="ma
}
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.
ASKER
How many points you want?
If you have more questions, then submit them as a new question.
ASKER
Thank for your suggestion. Your are so lovely!
<form action="mailto:anyone@anyw
<input type="submit">
</form>