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'])){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求恶意流量检测系统搭建教程( C++ python C)
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys