首页 > 开发 > PHP > 正文

通过html表格发电子邮件

2024-05-04 23:01:12
字体:
来源:转载
供稿:网友
如下:
<?  

/******************************************************************************  
description: this is a simple script to send emails via a html-form   
               to different users  
date        : 1999-02-25  
author        : amalesh kempf <[email protected]>  


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="[email protected]";  



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"    
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>";  
    }  
}  
?>  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表