Jump to content

Recommended Posts

Unable to submit choosing a file. This feature should be optional, Please assist. Thank you.

php code

=========

<?php
$page = 'contact';
require "header.php";
?>

<?php
$statusMsg='';
if(isset($_FILES["file"]["name"])){
   $email = $_POST['email'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $phone = $_POST['phone'];
    $company = $_POST['company'];
    $option = $_POST['option'];
    $message = $_POST['message'];
    
    if(!empty($_POST['check_list'])) {
    $checks = array();
    foreach($_POST['check_list'] as $check) {
        $checks[] = $check;
    }
    $check = implode('</br>&bull;', $checks);
}
$fromemail =  $email;
$subject="MyGeo - Contact Us";
$email_message = '<h2>User Information</h2>
                    <p><b>First Name:</b> '.$fname.'</p>
                    <p><b>Last Name:</b> '.$lname.'</p>
                    <p><b>Email:</b> '.$email.'</p>
                    <p><b>Phone:</b> '.$phone.'</p>
                    <p><b>Company:</b> '.$company.'</p>
                    <p><b>Please choose a category :</b> '.$option.'</p>
                    <p><b>Your message to MyGeo :</b> '.$message.'</p>';
$email_message.="Please find the attachment";
$semi_rand = md5(uniqid(time()));
$headers = "From: ".$fromemail;
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";

if($_FILES["file"]["name"]!= ""){  
    $strFilesName = $_FILES["file"]["name"];  
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["file"]["tmp_name"])));  
    
    
    $email_message .= "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $email_message .= "\n\n";


    $email_message .= "--{$mime_boundary}\n" .
    "Content-Type: application/octet-stream;\n" .
    " name=\"{$strFilesName}\"\n" .
    //"Content-Disposition: attachment;\n" .
    //" filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $strContent  .= "\n\n" .
    "--{$mime_boundary}--\n";
}
$toemail="jasmin.ambrose@mygeo.my"; 

if(mail($toemail, $subject, $email_message, $headers)){
   $statusMsg= "Submission succesful, thank you for contacting MyGeo";

}else{
   $statusMsg= "SUBMISSION FAILED, please submit again later, thank you";
}
}
   ?>

    <!-- Display submission status -->
<?php if(!empty($statusMsg)){ ?>
    <h1 class="container jumbotron text-uppercase text-center mx-auto" style="
    font-size: 25px;
    color: green;"><?php echo $statusMsg; ?></h1>
<?php } ?>
        <!-- Sectio-one -->

                <div class="col-md-12 square">
                    <h3 class="font-weight-bold"></h3>
                    <h4 class="font-weight-bold">MyGeo Sdn. Bhd. (1367062-K)</h4>
                    <h5>Level 2, Suite IIC Resource Centre,
                    Technology Park Malaysia,
                    Bukit Jalil,
                    57000 Kuala Lumpur,
                    MALAYSIA</h5>
                    <i class="fa fa-envelope-o" aria-hidden="true"></i>
                    contactus@mygeo.my &nbsp;
                    <i class="fa fa-phone" aria-hidden="true"></i>
                    +6012 345 3263
                </div>


    <div class="section-service py-5 my-1">
        <div class="container">
            <div class="row p-1">
                <div class="col-xs-6">
                    <h1>HOW CAN WE HELP YOU</h1>
                </div>
            </div>
            <div class="row p-1">
                <div class="col-md-12">
                    <p id="sep">Contact us below with new project requests, feedback and general questions</p>
                    <form method="post" action="" enctype="multipart/form-data">
                      <div class="form-row">
                        <div class="form-group col-md-6">
                            <label class="font-weight-bold" for="fname">First Name</label>
                          <input name="fname" type="text" class="form-control" placeholder="First name" required>
                        </div>
                        <div class="form-group col-md-6">
                            <label class="font-weight-bold" for="lname">Last Name</label>
                          <input name="lname" type="text" class="form-control" placeholder="Last name" >
                        </div>
                      </div>                        
                      <div class="form-row">
                        <div class="form-group col-md-6">
                          <label class="font-weight-bold" for="inputEmail4">Email</label>
                          <input name="email" type="email" class="form-control" id="inputEmail4" placeholder="Email" required>
                        </div>
                        <div class="form-group col-md-6">
                          <label class="font-weight-bold" for="Phone">Phone</label>
                          <input name="phone" type="tel" class="form-control" id="phone" placeholder="Enter phone number" required>
                        </div>
                      </div>

                      <div class="form-row">
                        <div class="form-group col-md-6">
                            <label class="font-weight-bold" for="company">Company</label>
                          <input name="company" type="text" class="form-control" placeholder="Company" >
                        </div>
                      </div>                        

                      <div class="form-row">
                        <div class="form-group">
                          <label class="font-weight-bold" for="input" required>Please choose a category :</label>
                          <div class="form-check">
                              <input class="form-check-input" <?php if (isset($option) && $option=="General Questions") echo "checked";?> value="General Questions" type="radio" name="option" id="exampleRadios1" checked>
                              <label class="form-check-label" for="exampleRadios1">
                                General Questions
                              </label>
                            </div>
                          <div class="form-check">
                              <input class="form-check-input" <?php if (isset($option) && $option=="New Project Request") echo "checked";?> value="New Project Request" type="radio" name="option" id="exampleRadios1" checked>
                              <label class="form-check-label" for="exampleRadios1">
                                New Project Request
                              </label>
                          </div>
                          <div class="form-check">
                              <input class="form-check-input" <?php if (isset($option) && $option=="Feedback") echo "checked";?> value="Feedback" type="radio" name="option" id="exampleRadios1" checked>
                              <label class="form-check-label" for="exampleRadios1">
                                Feedback
                              </label>
                            </div>
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="font-weight-bold" for="Textarea1">Your message to MyGeo</label>
                        <textarea class="form-control" id="FormTextarea1" rows="3" name="message" required></textarea>
                        <small id="emailHelp" class="form-text text-muted">0 of 4000 max charaacters</small>
                      </div>
                        <p></p>
                        <p></p>
                        <div class="form-group">
                            <label class="font-weight-bold" for="File1"></label>
                            <input type="file" name="file" class="form-control-file" id="exampleFormControlFile1" required ="">
                        </div>
                      <button type="submit" class="btn btn-success" name="submit">Submit</button>

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

<?php
require "footer.php";
?>

 

footer.php

=======

<!-- Footer -->
    <section id="footer">
        <div class="container text-center">
            <div class="row social">
                <div class="col-xs-12 col-sm-12 col-md-12 mt-2 mt-sm-2">
                    <ul>
                        <li class="list-inline-item">
                        <a href="#"><i class="fa fa-linkedin"></i></a></li>
                        <li class="list-inline-item">
                        <a href="#"><i class="fa fa-twitter"></i></a></li>
                        <li class="list-inline-item">
                        <a href="https://www.facebook.com/MyGeo-100967235334783"><i class="fa fa-facebook"></i></a></li>
                    </ul>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12 col-md-12 mt-2 mt-sm-2 text center text-white">
                    <p>&copy; All Rights Reserved (2020)<a href="#"> MyGeo</a> Sdn. Bhd. (1367062-K)</p>
                    <p>Level 2 Suite IIC Resource Centre Technology Park Malaysia, Bukit Jalil, 57000 Kuala Lumpur, MALAYSIA.</p>
                </div>
            </div>
        </div>
    </section>

    <script>
    function myFunction() {
      var input, filter, ul, li, a, i;
      input = document.getElementById("mySearch");
      filter = input.value.toUpperCase();
      ul = document.getElementById("myMenu");
      li = ul.getElementsByTagName("li");
      for (i = 0; i < li.length; i++) {
        a = li.getElementsByTagName("a")[0];
        if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
          li.style.display = "";
        } else {
          li.style.display = "none";
        }
      }
    }
    </script>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>

</body>
</html>

 

header.php

========

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>My GEO</title>
        <link rel="shortcut icon" type="image/png" href="images/mygeo logo2.png">
        <link rel="stylesheet" href="./css/style.css">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    </head>
    <body>
        <!-- Simple Responsive Navbar -->
       <nav class="navbar navbar-expand-xl text-success font-weight-600 pt-2">
        <div class="container">
            <a class="navbar-brand" href="index.php"><img style="width: 15vh;" src="images/mygeo logo2.png"></a>
            <button class="navbar-toggler navbar-light" data-toggle="collapse" data-target="#Nav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="Nav">
                <ul class="navbar-nav" id="myMenu">
                    <li class="nav-item <?php if($page=='about'){echo 'active';}?>">
                        <a class="nav-link" href="about.php">ABOUT US</a>
                    </li>
                    <li class="nav-item <?php if($page=='services'){echo 'active';}?>">
                        <a class="nav-link" href="services.php">SERVICES</a>
                    </li>
                    <li class="nav-item <?php if($page=='projects'){echo 'active';}?>">
                        <a class="nav-link" href="projects.php">PROJECTS</a>
                    </li>
                    <li class="nav-item <?php if($page=='people'){echo 'active';}?>">
                        <a class="nav-link" href="people.php">MYGEO PEOPLE</a>
                    </li>
                    <li class="nav-item dropdown <?php if($page=='careers'){echo 'active';}?>">
                        <a class="nav-link dropdown-toggle " data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">CAREERS</a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                        <a class="dropdown-item" href="career-a.php">TELL US ABOUT YOURSELF</a>
                        <a class="dropdown-item" href="career-b.php">JOB OPENINGS</a>
                        </div>
                    </li>
                    <li class="nav-item <?php if($page=='blog'){echo 'active';}?>">
                        <a class="nav-link" href="https://mygeomalaysia.wordpress.com/">BLOG</a>
                    </li>
                    <li class="nav-item <?php if($page=='webmail'){echo 'active';}?>">
                        <a class="nav-link"  target="_blank" href="https://mygeo.my/webmail">WEBMAIL</a>
                    </li>
                    <li class="nav-item <?php if($page=='contact'){echo 'active';}?>">
                        <a class="nav-link" href="contact-a.php">CONTACT US</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

 

phphelp1.png

Edited by requinix
please use the Code <> button when posting code
Link to comment
https://forums.phpfreaks.com/topic/312504-contact-us-form-not-working-properly/
Share on other sites

21 minutes ago, GVyran said:

Unable to submit choosing a file. This feature should be optional, Please assist. Thank you.

If you're looking to hire someone to do this work for you, the Job Offerings forum would be a more appropriate place.

If you want help doing this yourself then you can start by explaining how you tried to fix the code and what happened when you did.

12 hours ago, GVyran said:

<input type="file" name="file" class="form-control-file" id="exampleFormControlFile1" required ="">

The required attribute is being used on your file select.  Remove that and it will become optional.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.