用户在下面添加5封电子邮件及其名称,然后点击“发送”按钮后,我想发送消息,例如“您好,您的朋友'sendername'建议您使用thissite.com。请访问该网站。“我还想指定此电子邮件的起始地址。
PHP脚本可以做什么?
提前致谢,
约翰
<div class="email1">
<form method="post" action="friends.php">
email address of friend 1:<br>
<input name="email1" type="text" size="55"><br>
<br>
email address of friend 2:<br>
<input name="email2" type="text" size="55"><br>
<br>
email address of friend 3:<br>
<input name="email3" type="text" size="55"><br>
<br>
email address of friend 4:<br>
<input name="email4" type="text" size="55"><br>
<br>
email address of friend 5:<br>
<input name="email5" type="text" size="55"><br>
<br>
your name:<br>
<input name="sendername" type="text" size="55"><br>
<br>
<input type="submit" value="send" name="Send" id="Send"/>
</form>
答案 0 :(得分:1)
您可以使用php的mail功能。
代码将是这样的
$msg = "a message";
$subject = "a subject";
mail($_POST['email1'], $subject,$msg,'From: ' . $_POST['sendername'] . "\n\r" );
mail($_POST['email2'], $subject,$msg,'From: ' . $_POST['sendername'] . "\n\r" );
mail($_POST['email3'], $subject,$msg,'From: ' . $_POST['sendername'] . "\n\r" );
mail($_POST['email4'], $subject,$msg,'From: ' . $_POST['sendername'] . "\n\r" );
mail($_POST['email5'], $subject,$msg,'From: ' . $_POST['sendername'] . "\n\r" );
同时将表单更改为使代码更容易
<div class="email1">
<form method="post" action="friends.php">
email address of friend 1:<br>
<input name="email[]" type="text" size="55"><br>
<br>
email address of friend 2:<br>
<input name="email[]" type="text" size="55"><br>
<br>
email address of friend 3:<br>
<input name="email[]" type="text" size="55"><br>
<br>
email address of friend 4:<br>
<input name="email[]" type="text" size="55"><br>
<br>
email address of friend 5:<br>
<input name="email[]" type="text" size="55"><br>
<br>
your name:<br>
<input name="sendername" type="text" size="55"><br>
<br>
<input type="submit" value="send" name="Send" id="Send"/>
</form>
它会将代码重新编写为
希望这会有所帮助。
$msg = "a message";
$subject = "a subject";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,'From: ' . $_POST['sendername'] . "\n\r" );
}
您的评论代码
$msg = "<html><body><h1><a href="thissite.com">thissite</a></h1><img src='http://youserver.com/img.jpg'></body></html>";
$subject = "a subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
答案 1 :(得分:0)
只需获取那些POST变量并使用PHP中的mail()函数。这并不难
有关mail()的更多参考:http://php.net/manual/en/function.mail.php
答案 2 :(得分:0)
$to = $_POST['email1'];
$subject = 'your subject';
$message = 'Hello, your friend '.$_POST['sendername'].' recommends that you use thissite.com. Please visit the site.';
$headers = 'From: fromr@example.com' . "\r\n";
mail($to, $subject, $message, $headers);
在您需要的时间重复此过程。