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:
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:
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?
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("\n", $_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.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加