Page 1 of 1

Multiple Email (dropdown), how to send

Posted: Sun Aug 11, 2002 11:00 am
by SilvrWolf
I have a form that is to be filled out. I then want to send it, but it could be sent to different people. The user chooses the receipient via a dropdown. Since I know nothing of javascript and I don't rightly know that php is the way to do this, does anyone have any suggestions?

Posted: Sun Aug 11, 2002 11:38 am
by volka
first the diffrent kinds of html-forms that may be used

Code: Select all

<html><body>
<form method="POST">
	<select name="email_target">
		<option>recipient1@some.whe.re</option>
		<option>recipient2@some.whe.re</option>
		<option>recipient3@some.whe.re</option>
		<option>recipient4@some.whe.re</option>
		<option>recipient5@some.whe.re</option>
		<option>recipient6@some.whe.re</option>
	</select>
	<br/>
	<input type="submit"/>
</form>
<pre>
<?php
	print_r($_POST);
?> 
</pre>
</body>
</html>
you'll see a comb(-dropdown-)box with all 'options' to select but only one at a time. If submitted the selected value will be in the super-global array $_POST.

Code: Select all

<html><body>
<form method="POST">
	<select name="email_target&#1111;]" size="5" multiple="true">
		<option>recipient1@some.whe.re</option>
		<option>recipient2@some.whe.re</option>
		<option>recipient3@some.whe.re</option>
		<option>recipient4@some.whe.re</option>
		<option>recipient5@some.whe.re</option>
		<option>recipient6@some.whe.re</option>
	</select>
	<br/>
	<input type="submit"/>
</form>
<pre>
<?php
	print_r($_POST);
?> 
</pre>
</body>
</html>
displays a listfield with 5 values in view, multiple selections are possible. take care the name of the select-element ends with [], meaning an array (multiple selections) are to be recorgnized.
again $_POST holds the selected values. But this time the index email_target is not a string but an array - always starting at index 0

Code: Select all

<html><body>
<form method="POST">
	<select name="email_target">
		<option>recipient1@some.whe.re</option>
		<option>recipient2@some.whe.re</option>
		<option>recipient3@some.whe.re</option>
		<option>recipient4@some.whe.re</option>
		<option>recipient5@some.whe.re</option>
		<option>recipient6@some.whe.re</option>
	</select>
	<br/>
	<input type="submit"/>
</form>
<pre>
<?php
   if (isset($_POST&#1111;'email_target'])
      mail($_POST&#1111;'email_target'], "greetings", "you have been greeted");
?> 
</pre>
</body>
</html>
or

Code: Select all

<html><body>
<form method="POST">
	<select name="email_target&#1111;]" size="5" multiple="true">
		<option>recipient1@some.whe.re</option>
		<option>recipient2@some.whe.re</option>
		<option>recipient3@some.whe.re</option>
		<option>recipient4@some.whe.re</option>
		<option>recipient5@some.whe.re</option>
		<option>recipient6@some.whe.re</option>
	</select>
	<br/>
	<input type="submit"/>
</form>
<pre>
<?php
   foreach($_POST&#1111;'email_target'] as $recp)
      mail($recp, "greetings", "you have been greeted");
?> 
</pre>
</body>
</html>
would be very basic mail-scripts

$_POST
print_r
foreach
mail

this is a server-side solution. so the emails will be sent from the hosting server via it's smpt-server.

client-side you would use javascript and (probably) the mailto: syntax for document.href. mails would be sent via the users mail-client

email: client side

Posted: Mon Sep 02, 2002 11:18 am
by gite_ashish
hi,

pls find below the most crude/cryptic/dump.... BUT yet the most simplest to code method of form-2-email:

Code: Select all

<H1>Form-2-Email</H1>
<PRE>
<FORM name=frm action="mailto:user@domain.com?subject=form-2-email" method=POST>
    Name: <INPUT type=text name=txtName>
    Phone: <INPUT type=text name=txtPhone>

    Select OS:
    <INPUT type=checkbox name=chkos1 value=win>Windows
    <INPUT type=checkbox name=chkos2 value=linux>Linux

    Select User Agent:
    <INPUT type=radio name=rdoua value=ie>Internet Explorer
    <INPUT type=radio name=rdoua value=nn>Netscape Navigator

    Notes:
    <TEXTAREA name=txaNotes cols=30 rows=5></TEXTAREA>

    Month:
    <SELECT name="MonthOfBirth">
        <OPTION VALUE="1">January</OPTION>
        <OPTION VALUE="2">February</OPTION>
        <OPTION VALUE="3">March</OPTION>
        <OPTION VALUE="4">April</OPTION>
        <OPTION VALUE="5">May</OPTION>
        <OPTION VALUE="6">June</OPTION>
        <OPTION VALUE="7">July</OPTION>
        <OPTION VALUE="8">August</OPTION>
        <OPTION VALUE="9">September</OPTION>
        <OPTION VALUE="10">October</OPTION>
        <OPTION VALUE="11">November</OPTION>
        <OPTION VALUE="12">December</OPTION>
    </SELECT>

    <INPUT type=submit value=Email>
</FORM>
</PRE>

regards,

email: client side (v2)

Posted: Mon Sep 02, 2002 11:35 am
by gite_ashish
Hi,

following code is ver2 of my earlier post. it does actually what u want on client side. the updated part is in bold.

Code: Select all

&#1111;b]<SCRIPT type="text/javascript">

    function setTo()
    &#123;
        document.frm.action = document.frm.to.options&#1111;document.frm.to.selectedIndex].value;
    &#125;

</SCRIPT>&#1111;/b]

<PRE>
<H3>Form-2-Email</H3>
<FORM name=frm method=POST &#1111;b]onSubmit="setTo();"&#1111;/b]>
&#1111;b]    To: <SELECT name=to>
        <OPTION value="mailto:user1@domain1.com?subject=form-2-email">user1@doma
in1.com</OPTION>
        <OPTION value="mailto:user2@domain2.com?subject=form-2-email">user2@doma
in2.com</OPTION>
        <OPTION value="mailto:user3@domain3.com?subject=form-2-email">user3@doma
in3.com</OPTION>
    </SELECT>&#1111;/b]

    Name: <INPUT type=text name=txtName>
    Phone: <INPUT type=text name=txtPhone>

    Select OS:
    <INPUT type=checkbox name=chkos1 value=win>Windows
    <INPUT type=checkbox name=chkos2 value=linux>Linux

    Select User Agent:
    <INPUT type=radio name=rdoua value=ie>Internet Explorer
    <INPUT type=radio name=rdoua value=nn>Netscape Navigator

    Notes:
    <TEXTAREA name=txaNotes cols=30 rows=5></TEXTAREA>

    Month: <SELECT name="MonthOfBirth">
        <OPTION VALUE="1">January</OPTION>
        <OPTION VALUE="2">February</OPTION>
        <OPTION VALUE="11">November</OPTION>
        <OPTION VALUE="12">December</OPTION>
    </SELECT>

    <INPUT type=submit value=Email>
</FORM>
</PRE>

email: server side

Posted: Mon Sep 02, 2002 11:44 am
by gite_ashish
hi,

for server side (php) email sending program you can use the php's builtin function mail(), -OR- if compiled with imap support can use imap_mail().

see the php man for details:

mail() -- http://www.php.net/manual/en/function.mail.html
imap_mail() -- http://www.php.net/manual/en/function.imap-mail.html


regards,

email: server side (recent posts)

Posted: Mon Sep 02, 2002 11:47 am
by gite_ashish
hi,

for server side email related info see few recent posts also:

1. http://www.devnetwork.net/forums/viewtopic.php?t=2698
2. http://www.devnetwork.net/forums/viewtopic.php?t=2678


regards,