欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过html表格发电子邮件

程序员文章站 2022-04-20 10:12:34
如下:
如下:
<?  

/******************************************************************************  
description: this is a simple script to send emails via a html-form   
               to different users  
date        : 1999-02-25  
author        : amalesh kempf <amalesh@goatrance.de>  


create this table  
the field "what" is for different categories  

create table email_notify (  
id int(11) default '0' not null,  
what varchar(60) default '0' not null,  
name varchar(60) default '0' not null,  
email varchar(60) default '0' not null,  
timestamp varchar(16),  
key (what),  
primary key (id));  

to fill this table you might create an insert form  

*******************************************************************************/  




// set this values:  
$strhost  ="localhost";  
$struser  ="root";  
$strpassw ="";  
$strsender="you@domain.com";  



if (!$btnsendemail)  
{  
?>  

the email will be added automatically with "hello name" in the first line of   
the emailbody!<br>  
<br>  

    <form action="send_email.php3" enctype="application/x-www-form-  
urlencoded" method="post">  
    <table>  
        <tr>  
            <td>subject</td>  
            <td><input name="strsubject" size="40"></td>  
        </tr>  
        <tr>  
            <td>body</td>  
            <td><textarea cols="40" name="strbody" rows="8"   
wrap="physical"><? echo $strbody ?></textarea></td>  
        </tr>  
        <tr>  
            <td>category</td>  
            <td>  
                <select name="strwhat">  
                <?php // add you categories here: ?>  
                <option value="party">party</option>  
                </select>  
            </td>  
        </tr>  
    </table>  
    <input name="btnsendemail" style="height: 24px; width: 224px"   
type="submit" value="sende email">  
    </form>  

<?php  
}  


if (isset($btnsendemail))  
{    echo "send email<br>";  

    // create connection  
    $intconid = mysql_pconnect($strhost,$struser,$strpassw);  

    // header  
    $strheader = "return-path: $strsender\nerrors-to: $strsender\nfrom:   
$strsender";  

    // sql  
    $strsql = "select name,email from email_notify where lcase(what) =   
'$strwhat'";  
    $intres = mysql_query($strsql,$intconid);  

    echo "send email $strbody<br>";  

    // fetch array      
    while($sarow = mysql_fetch_array($intres))  
    {    $stremail = $sarow["email"];  
        $strname = $sarow["name"];  
        $strbodycomplete = "hello " . $strname[$i] . "!\n\n" . $strbody;  

        // email  
        mail($stremail,$strsubject,$strbodycomplete,$strheader);  

        // output  
        echo "send to $strname<br>";  
    }  
}  
?>