0

This may look familiar easy for all of you. Please take time to help me out

I get to used the codes of PHPMailer for sending email using Gmail as my SMTP Server. But when i check if it still works the send email. The codes is properly working but i haven't receive the mail. I've been reading different threads and blogs that may help me to figure it out. But none of them give me an idea to resolve the problem.

Some thread says that there's a bug with PHP 5.5 when it comes to port they say that just set the port as 25

Someone says that Allow less secure apps:ON of google. I followed them too.

There's no error occurring in my situation. I dont receive any mail from this code.

The following codes was working before, but when i tried now. It's not working anymore.

Here's my index.html:

<form id="contact-us" method="post" action="MAIL/index.php">
   <!-- Left Inputs -->
   <div class="col-xs-6 ">
   <input type="text" name="name" id="name" class="form" placeholder="Full-name *" required/>
   <!-- Email -->
    <input type="email" name="email" id="email" class="form" placeholder="Email *" required/>
    <select name="category" id="secondayject" class="form" required>
    <option value="" disabled selected>Choose your option: Web App, Design, and Support. *</option>
    <option value="WEBAPPDEV">Web Application Development</option>
    <option value="WEBDESIGN">Web Design</option>
    <option value="WEBSUPPORT">Web Support</option>
    </select>
   </div><!-- End Left Inputs -->
  <!-- Right Inputs -->
     <div class="col-xs-6">
   <!-- Message -->
   <textarea name="message" id="message" class="form textarea"  placeholder="Message"></textarea>
   </div><!-- End Right Inputs -->
    <!-- Bottom secondaymit -->
    <div class="relative fullwidth col-xs-12">
    <!-- Send Button -->
    <button type="submit" id="secondaymit" name="submit" class="form-btn semibold"><span class="fa fa-envelope-o"></span>&nbsp;Send Message</button> 
   </div><!-- End Bottom secondaymit -->
    <!-- Clear -->
   <div class="clear"></div>
  </form>

Here's my MAIL/index.php (code of PHPMailer)

include("../../private/db_connection.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
 require 'vendor/autoload.php';

 $mail = new PHPMailer(true); 
 try {
$connect = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$message = htmlspecialchars($_POST['message']);
$client_name = $_POST['name'];
$client_email = $_POST['email'];
$client_category = $_POST['category'];
date_default_timezone_set('Asia/Manila');
$datetime = "Date: " .date('D, M j, Y at g:ia');

$query = "INSERT INTO akingrg VALUES('','".$client_name."','".$client_email."','".$client_category."','".$message."',now())";
$data = $connect->query($query);
$to = $client_email;
$subject = $client_category;



include("../../private/mail_auth.php");

$mail->setFrom('sample@gmail.com', 'THISISME');
$mail->addAddress($client_email, $client_name);     // Add a recipient
$mail->isHTML(true);
$mail->Subject = $client_category.' | THIS IS ME';

$mail->Body = "
 This is just my html body that will inform the user that they filled up.
";
$mail->send();
 ?>
        <script>
        alert('Thankyou, Ill get back to you soon!');
        window.location.href='https://samplesite.com';
        </script>
<?php
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

Here's my ../../private/db_connection.php

$host = "127.0.0.1";
$username = "secret";
$password = "secret";
$database = "secret";

Here's my ../../private/mail_auth.php

$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'sample@gmail.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
Pablo
  • 1,357
  • 1
  • 11
  • 40

0 Answers0