我已经遍布整个互联网试图找到答案但却一无所获。
我的网站上有一个注册按钮,当有人注册他们的电子邮件时,我希望有两件事情发生:
我目前有一个附加了mail()函数的注册表单,但我只能弄清楚如何使用它来发送一条消息。到目前为止,我只是用它来通知我。
有没有办法发送多条消息?
HTML表单:
<form method="post" action="signup.php">
<input type="text" name="email" placeholder="Email" class="content2"/>
<input type="submit" class="special" value="Submit" />
</form>
contact.php是
<?php
$email = $_REQUEST['email'] ;
$headers .= "Reply-To: My Site <my@email.com>\r\n";
$headers .= "Return-Path: My Site <my@email.com>\r\n";
$headers .= "From: My Site <my@email.com>\r\n";
mail( "my@email.com", "Signup Request", "Signup request from $email", "$headers" );
header( "Location: thankyou.html" );
?>
答案 0 :(得分:0)
正如其他人所建议的那样,您可以轻松使用2个邮件功能:
<?php
$email = $_REQUEST['email'] ;
$headers .= "Reply-To: My Site <my@email.com>";
$headers .= "Return-Path: My Site <my@email.com>";
$headers .= "From: My Site <my@email.com>";
mail( "my@email.com", "Signup Request", "Signup request from $email", "$headers" );
mail( "my@email.com", "Welcome", "Welcome to this site!", "$headers" );
header( "Location: thankyou.html" );
?>
如果您只想使用1个邮件功能,可以使用数组和 for 循环,如下所示:
<?php
$email = $_REQUEST['email'] ;
$headers .= "Reply-To: My Site <my@email.com>";
$headers .= "Return-Path: My Site <my@email.com>";
$headers .= "From: My Site <my@email.com>";
$subject = array("Signup Request", "Welcome");
$content = array("Signup request from $email", "Welcome to this site!");
for($i = 0; $i < count($content); $i++;){
mail( "my@email.com", $subject[$i], $content[$i], "$headers" );
}
header( "Location: thankyou.html" );
?>
这是一个Muddal教程,介绍如何更深入地完成此任务:https://muddal.com/muddaltut.php?id=140