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.

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

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起