[英]PHPMailer not sending any email
I am using PHPMailer library to send email but it is not sending any email,I tried since morning but still I am unable to send any email it is showing error this page is not working phpmailer.php,smtp and test.php in same directory help me to solve this issue.我正在使用 PHPMailer 库发送电子邮件,但它没有发送任何电子邮件,我从早上开始尝试,但仍然无法发送任何电子邮件它显示错误该页面在同一目录中无法正常工作 phpmailer.php,smtp 和 test.php帮我解决这个问题。 Code in test.php
test.php 中的代码
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//require 'vendor/autoload.php';
include("PHPMailer.php");
include("SMTP.php");
include("Exception.php");
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc@gmail.com'; // SMTP username
$mail->Password = 'xxxxx'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('abc@gmail.com', 'Mailer');
$mail->addAddress('receiver@gmail.com', 'Joe User'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
Error:错误:
Simple fix!简单修复!
$mail->Host
is a web request not a socket and 465 is the wrong port! $mail->Host
是网络请求而不是套接字,465 是错误的端口! Try尝试
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
example: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps示例: https : //github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.