0

I have created one contact us form but there you be two submit button:

  1. Button name submit will go to data this email address: sm.musa.cse@gmail.com
  2. Button name very urgent will go to data these two email address sm_musa@hotmail.co.uk and s_m_musa@yahoo.com

I coded php in separated page and form in the index page but it’s not working. Here is the code below:

HTML code:

<form action="bin/MailHandler.php" id="ContactForm" method="post">
    <div class="success"> Contact form submitted!>
        <br />
        <strong>We will be in touch soon.</strong> 
    </div>
    <fieldset>
        <div class="wrapper">
            <label class="name">
                <span class="bg">
                    <input type="text" name="name" value="Name:" class="input" />
                </span>
                <span class="error">*This is not a valid name.</span>
                <span class="empty">*This field is required.</span>
            </label>
        </div>
        <div class="wrapper">
            <label class="email">
                <span class="bg">
                    <input type="text" name="email" value="E-mail:" class="input" />
                </span>
                <span class="error">*This is not a valid email address.</span>
                <span class="empty">*This field is required.</span>
            </label>
        </div>
        <div class="wrapper">
            <label class="phone">
                <span class="bg">
                    <input type="tel" name="phone" value="Phone:" class="input" />
                </span>
                <span class="error">*This is not a valid phone number.</span>
                <span class="empty">*This field is required.</span>
            </label>
        </div>
        <div class="wrapper">
            <label class="message">
                <span class="bg">
                    <textarea rows="1" cols="1" name="message">Message:</textarea>
                </span>
                <span class="error">*The message is too short.</span>
                <span class="empty">*This field is required.</span>
            </label>
        </div>
        <div class="btns">
            <input name="first_email_send" type="submit" value="submit" />
        </div>
        <div class="btns">
            <input name="second_email_send" type="submit" value="very urgent" />
        </div>
    </fieldset>
</form>

php code:

<?php
    $name= $_POST['name'];
    $email= $_POST['email'];
    $phone= $_POST['phone'];
    $message= $_POST['message'];


    $to1="sm.musa.cse@gmail.com";
    $to2_1="sm_musa@hotmail.co.uk";
    $to2_2="s_m_musa@yahoo.com";

    $subject="You Have Recieved Mail From Customer";
    $mess1= $name.$phone.$message."MUSA VAI JEITA ICCA SEITA LEKO";
    $mess2_1= $name.$phone.$message."MUSA VAI JEITA ICCA SEITA LEKO";
    $mess2_2= $name.$phone.$message."MUSA VAI JEITA ICCA SEITA LEKO";


    //$send_contact= mail( $to,$subject,$email,$mess);
    if(isset($_POST['first_email_send']))
    {

        $send_contact= mail( $to1,$subject,$email,$mess1);
        if($send_contact){
            echo "Thank for submitting you details we've received your Details. One of our sales member contact you as soon as possible";
        }
        else {
        echo "ERROR";
        }
    }
    if(isset($_POST['second_email_send']))
    {
        $send_contact1= mail( $to2_1,$subject,$email,$mess2_1);
        $send_contact2= mail( $to2_2,$subject,$email,$mess2_2);
        if($send_contact1 && $send_contact2){
            echo "Thank for submitting you details we've received your Details. One of our sales member contact you as soon as possible";
        }
        else {
            echo "ERROR";
        }
    }
    /*if($send_contact){
    echo "Thank for submitting you details we've received your Details. One of our sales member contact you as soon as possible";
    }
    else {
    echo "ERROR";
    }*/
?>  
Azathoth
  • 582
  • 1
  • 7
  • 29
  • Define 'not working' My guess is you never define `$to1` or `$to2_1` or `$to2_2` that we can see. – Jon Apr 02 '13 at 10:39
  • This is not a javascript question, so javascript tag should be removed. – vdua Apr 02 '13 at 11:03

1 Answers1

0

The issue is the way you are checking for how data is submitted. You need to change two things

Make the name of submit buttons same, say "submit"

    <div class="btns">
        <input name="submit" type="submit" value="submit" />
    </div>
    <div class="btns">
        <input name="submit" type="submit" value="very urgent" />
    </div>

Post Data is submitted as key value pairs. Value of the submit button will hint you which button was clicked.

Check the value of the 'submit' parameter in the POST and then make a decision. i.e modify your php code like this

if($_POST['submit'] == 'submit')
{

    $send_contact= mail( $to1,$subject,$email,$mess1);
    if($send_contact){
        echo "Thank for submitting you details we've received your Details. One of our sales member contact you as soon as possible";
    }
    else {
         echo "ERROR";
    }
}
if($_POST['submit'] == 'very urgent')
{
    $send_contact1= mail( $to2_1,$subject,$email,$mess2_1);
    $send_contact2= mail( $to2_2,$subject,$email,$mess2_2);
    if($send_contact1 && $send_contact2){
        echo "Thank for submitting you details we've received your Details. One of our sales member contact you as soon as possible";
    }
    else {
        echo "ERROR";
    }
}

Reference: https://stackoverflow.com/a/56/1523245

Community
  • 1
  • 1
vdua
  • 1,281
  • 1
  • 14
  • 24