PHP Build a Basic PHP Website (2018) Adding a Basic Form Utilizing Object Properties and Methods

Dhruva Goyal
Dhruva Goyal
Full Stack JavaScript Techdegree Student 4,138 Points

No Mail Recieved Using Xampp.. sending mail to gmail

<?php 

if($_SERVER["REQUEST_METHOD"] == "POST"){
    $name = trim(filter_input(INPUT_POST,"name",FILTER_SANITIZE_STRING));
    $email = trim(filter_input(INPUT_POST,"email",FILTER_SANITIZE_EMAIL));
    $details = trim(filter_input(INPUT_POST,"details",FILTER_SANITIZE_SPECIAL_CHARS));

    if($name == "" OR $email == "" OR $details == ""){
        echo "Please fill in the required fields: Name, Email and Details";
        exit;
    }
    if($_POST["address"] != ""){
        echo "Bad Form Input";
        exit;
    }

    require 'inc/phpmailer/class.phpmailer.php';
    $mail = new PHPMailer;
    $mail->setFrom($email, $name);
    $mail->addAddress('My Mail', 'My Name');   
    $mail->isHTML(false);                              
    $mail->Subject = 'Here is the subject';
    $mail->Body    = $details;
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } 
    header("location:suggest.php?status=thanks");
}
$pageTitle = "Suggest a Media Item";
$section = "suggest";

include("inc/header.php"); ?>

<div class="section page">
        <div class="wrapper">
    <h1>Suggest a Media Item</h1>
    <?php 
    if(isset($_GET["status"]) && $_GET["status"] == "thanks") {
        echo "<p>Thanks for the message! will check out your suggestion shortly!!</p>";
    }
    else{
    ?>
    <p>If you think there is something I&rsquo;m Missing Let me know!</p>
    <form method="post" action="suggest.php">
    <table>
    <tr>
        <th><label for="name">Name</label></th>
        <td><input type="text" id="name" name="name" /></td>
    </tr>   
    <tr>
        <th><label for="email">Email</label></th>
        <td><input type="text" id="email" name="email" /></td>
    </tr>   
    <tr>
        <th><label for="details">Suggest Item Details</label></th>
        <td><textarea name="details" id="details"></textarea></td>
    </tr>   
    <tr style="display:none">
        <th><label for="address">Address</label></th>
        <td><input type="text" id="address" name="address" /><p>Please Leave Blank</p></td>
    </tr>
    </table>
    <input type="submit" value="Send" />
    </tr>
    </form>
    <?php } ?>  
        </div>
    </div>

<?php include("inc/footer.php"); ?>

^My code Hi Everyone. I am doing this locally. i have done the whole thing that way. the thing works no errors.. but im not getting a mail either could anyone tell me whats happening??

Through local server i.e. xamp mail function didn't work you have to upload it live on web or configure the SMTP settings for that. Check out for more http://www.codexworld.com/how-to-send-email-from-localhost-in-php/