当我尝试键入new PHPMailer(true);时,它总是给出同样的错误:
Undefined type 'PHPMailer\PHPMailer\PHPMailer'.
你能说出什么问题吗?谢谢!
代码:
<?php
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
require "vendor/autoload.php";
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.rackhost.hu";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->Username = "mail@jarkoricsi.hu";
$mail->Password = "Teszt123";
$mail->setFrom("mail@jarkoricsi.hu", "Djalms");
$mail->addAddress("alma.katica222@gmail.com");
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
echo "email sent";
?>用户名、密码和setFrom都是空的,以保持隐私。
发布于 2022-10-20 17:19:22
如果您现在已经成功地用composer安装了PHPMailer (这将解释为什么要获得类未找到的错误),我想504是由以下设置组合造成的:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 465;这要求它在端口上执行显式TLS,期望隐式TLS不能工作,但可能需要很长时间才能失败,从而导致504错误。区别是在文档中解释,但这两种组合中的任何一种都应该有效:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;或
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;https://stackoverflow.com/questions/74142307
复制相似问题