这对大家来说都很容易熟悉。请花时间帮助我
我使用PHPMailer的代码将Gmail用作SMTP服务器来发送电子邮件。但是当我检查它是否仍然可以发送电子邮件时。代码正常工作,但是我没有收到邮件。我一直在阅读不同的主题和博客,这可能有助于我弄清楚。但是他们都没有给我一个解决问题的想法。
一些线程说 PHP 5.5在端口方面存在一个错误,他们说只需将端口设置为25
有人说 允许安全性较低的应用程序:启用Google的。 我也跟着他们。
我的情况没有发生任何错误。我没有收到来自此代码的任何邮件。
以下代码以前可以工作,但是当我现在尝试时。它不再工作了。
这是我的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> Send Message</button>
</div><!-- End Bottom secondaymit -->
<!-- Clear -->
<div class="clear"></div>
</form>
这是我的MAIL / index.php(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;
}
这是我的../../ private / db_connection.php
$host = "127.0.0.1";
$username = "secret";
$password = "secret";
$database = "secret";
这是我的../../ 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;