[英]PHPMailer not working
I have tried my best to recieve message on a gmail account using phpmailer but i can't.我已尽力使用 phpmailer 在 gmail 帐户上接收消息,但我不能。 It shows message sent successfully but i don't recieve any message.它显示消息发送成功,但我没有收到任何消息。 I even edited the sendmail.ini file.我什至编辑了 sendmail.ini 文件。 This is the code:这是代码:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
//$mail->SMTPDebug = 2;
//$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail@gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 587;
$mail->setFrom('myemail@gmail.com', 'Mailer');
$mail->addAddress('example@gmail.com', 'Joe User');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
if($mail->send()){
echo 'Message has been sent successfully';
} else {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
I no so many questions concerning this have been answered but i still need help我没有回答这么多关于这个的问题,但我仍然需要帮助
Change setFrom
to SetFrom
and try to change IP
to 465
.更改setFrom
到SetFrom
并试图改变IP
到465
。 You can also try the following.您也可以尝试以下方法。
$mail = new PHPMailer();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$mail->SetFrom("example@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email@gmail.com");
if($mail->send()){
echo 'Message has been sent successfully';
} else {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
If you still get error than provide the error message.如果您仍然收到错误,请提供错误消息。
try:尝试:
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
Hope it will help.希望它会有所帮助。
First of all, try to uncomment line首先,尝试取消注释行
$mail->isSMTP(); $mail->isSMTP();
If you send mail via https, try to add following code:如果您通过 https 发送邮件,请尝试添加以下代码:
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.