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

三个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>

<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'])){