dongzan7016 2015-03-08 19:09
浏览 146
已采纳

如何将邮件中的电子邮件地址添加到文本框?

I'm making a webpage to send a list of email addresses to each user. I have a script called add_book.php to allow me to input a list of email addresses in the message like this:

http://oi57.tinypic.com/ra2nhw.jpg

I want to output a list of email addresses to input each of them in the textbox include with a comma when I click on the button to allow me to input the list of email addresses in the script called email.php, but I have no idea how to do this.

Like this:

http://oi60.tinypic.com/261yhl3.jpg

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Add Email Addresses...</title>
    </head>
    <body>
    <table>
        <tr>
            <td><textarea name="message" cols="50" rows="20"></textarea></td>

        </tr>
        <td colspan="2" align="left">
           <input type="submit" name="send" value="Add Email" style="height:35px; width:100px">
        </td>
    </table>
    </form>
    </body>

Here is the code for the email.php script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Send Email</title>
    <link type="text/css" rel="stylesheet" href="style.css"  />
    </head>
    <body>
    <form action="pr_send.php" method="POST">
    <table> 
        <!-- <tr>
            <td>From:</td>
            <td><input type="text" name="from"></td>
        </tr> -->
        <tr>
            <td><input type="button" name="to" value="" style="height:24px; width:24px; background:url('addressbook.png'); border:none;" onClick="Popup()"> To:</td> 
            <td><input type="text" name="to" style="height:15px; width:650px"></td> 
        </tr>
        <tr>
            <td>Subject:</td>
            <td><input type="text" name="subject" style="height:15px; width:650px"></td>
        </tr>
        <tr>
            <td>Message:</td>
            <td><textarea name="message" cols="90" rows="20"></textarea></td>
        </tr>

        <tr>
            </br>
            <td colspan="2" align="left">
               <input type="submit" name="send" value="" style="height:35px; width:100px; background:url('send.png'); border:none">
            </td>
        </tr>

    </table>
    </form>
    </body>
<script type="text/javascript">
function Popup() 
{
  window.open("add_address.php", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400");
}
</script>

</html>

Here is the textbox that I want to output with a list of email addresses:

<td><input type="text" name="to" style="height:15px; width:650px"></td> 

Can you please help me how I can extract a list of email addresses with a comma to output them in the textbox from the script add_address.php to my script called email.php?

  • 写回答

1条回答 默认 最新

  • dongyan1974 2015-03-08 19:19
    关注

    Several assumptions in here and this really isn't the best way to approach things.

    First you need to append the following line to the HTML in your add_address.php script just above the <table> tag:

    <form action="email.php" method="post">
    

    Without that line your form isn't going to submit anything anywhere when you click the button. The second thing to realise is that even doing this step means that your email.php page is going to open in the window you've open. Your submit, as it stands, is not going to update the email.php that you opened the window from.

    That aside here's how you would then capture this.

    Assuming that the data is going be email addresses on individual lines then you could do the following in email.php at the top of the page

    <?php
        if (!empty($_POST['message'])) {
            $emails = explode("
    ", $_POST['message']); // explode textarea on a line break into an array
            $email_str = implode(",", $emails); // take each of the emails and implode together with the ,
         }
    ?>
    

    You could then refer to $email_str with an echo

    <input type="text" name="to" value="<?php if (!empty($email_str)) { echo $email_str; } ?>">
    

    That should take the content of the textarea and transpose it to a comma separated string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?