duanre4421 2017-02-13 03:26
浏览 24
已采纳

三个php在同一页面上发送邮件表单,点击首先提交所有三封邮件

I have three php mail send form on same page. When I fill and submit the first form, the other two are also submitted, with empty value and send mail to their emails.

All three mail forms have to send email on different mail address. Please help me solve this issue.

As I click on first form submit only first form should send email and print echo. But here all echo prints and all mail are sent in once.

<?php 
if(isset($_POST['submit'])){
$to = "naveedtubasum@gmail.com"; // this is your Email address
$from = $_POST['o_email']; // this is the sender's Email address

$o_email = $_POST['o_email'];

$o_address = $_POST['o_address'];

$subject = "buy alert from aluta";
//$subject2 = "Copy of your from Aluta";
$message =" Hi, admin, you have an message from OFFICE  
 Message: ". $o_address ." 
Product link: 

" . $_POST['message'];
// $message2 = "Here is a copy of your message " . $s_name . "

" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
//mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "<h3>Mail Sent. Thank you " . $s_name . ", You will be contacted now.<h3>";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>

<div class="modal fade" id="office" role="dialog">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">GET UPDATED ON THE DIME</h4>
            </div>
            <div class="modal-body">
                <form method="post" action="" class="form-horizontal">
                    <div class="form-group">

                        <div class="col-sm-12">
                            <input type="email" class="form-control" name="o_email" placeholder="Enter email">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12"> 
                            <textarea type="text" class="form-control" rows="8" name="o_address" placeholder="I'm Intrested in retail space"></textarea>
                        </div>
                    </div>
                    <style>
                    .btn-default {
                        color: #fff;
                        background-color: #080808;
                        border-color: #ccc;}
                        </style>
                        <div class="form-group"> 
                            <div class="col-sm-12">
                                <input type="submit" name="submit" class="btn-block btn btn-default" value="Submit"/>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>

    <?php 
    if(isset($_POST['submit'])){
$to = "naveedtubasum2@gmail.com"; // this is your Email address
$from = $_POST['s_email']; // this is the sender's Email address

$s_email = $_POST['s_email'];

$s_address = $_POST['s_address'];

$subject = "buy alert from aluta";
//$subject2 = "Copy of your from Aluta";
$message =" Hi, admin, you have an message from RESIDENCES  
 Message: ". $s_address ." 
Product link: 

" . $_POST['message'];
// $message2 = "Here is a copy of your message " . $s_name . "

" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
//mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "<h3>Mail Sent. Thank you " . $s_name . ", You will be contacted now.<h3>";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>


<div class="modal fade" id="residences" role="dialog">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">GET UPDATED ON THE DIME</h4>
            </div>
            <div class="modal-body">
                <form method="post" action="" class="form-horizontal">
                    <div class="form-group">

                        <div class="col-sm-12">
                            <input type="email" class="form-control" name="s_email" placeholder="Enter email">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12"> 
                            <textarea type="text" class="form-control" rows="8" name="s_address" placeholder="I'm Intrested in retail space"></textarea>
                        </div>
                    </div>

                    <div class="form-group"> 
                        <div class="col-sm-12">
                            <input type="submit" name="submit" class="btn-block btn btn-default" value="Submit"/>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>



<?php 
if(isset($_POST['submit'])){
$to = "naveedtubasum3@gmail.com"; // this is your Email address
$from = $_POST['r_email']; // this is the sender's Email address

$r_email = $_POST['r_email'];

$r_address = $_POST['r_address'];

$subject = "buy alert from aluta";
//$subject2 = "Copy of your from Aluta";
$message =" Hi, admin, you have an message from OFFICE  
 Message: ". $r_address ." 
Product link: 

" . $_POST['message'];
// $message2 = "Here is a copy of your message " . $s_name . "

" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
//mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "<h3>Mail Sent. Thank you " . $s_name . ", You will be contacted now.<h3>";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<div class="modal fade" id="retail" role="dialog">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">GET UPDATED ON THE DIME</h4>
            </div>
            <div class="modal-body">
                <form method="post" action="" class="form-horizontal">
                    <div class="form-group">

                        <div class="col-sm-12">
                            <input type="email" class="form-control" name="r_email" placeholder="Enter email">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12"> 
                            <textarea type="text" class="form-control" rows="8" name="r_address" placeholder="I'm Intrested in retail space"></textarea>
                        </div>
                    </div>

                    <div class="form-group"> 
                        <div class="col-sm-12">
                            <input type="submit" name="submit" class="btn-block btn btn-default" value="Submit"/>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>
  • 写回答

1条回答 默认 最新

  • duanqian2368 2017-02-13 03:30
    关注
    <input type="submit" name="submit" class="btn-block btn btn-default" value="Submit"/>
    
    if(isset($_POST['submit'])){
    

    You're using the same name for each form submit button. Make each pair unique.

    <input type="submit" name="submit1" class="btn-block btn btn-default" value="Submit"/>
    
    if(isset($_POST['submit1'])){
    
    
    
    <input type="submit" name="submit2" class="btn-block btn btn-default" value="Submit"/>
    
    if(isset($_POST['submit2'])){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么