Openssl PHPMailer/SMTP/LimeSurvey的权限被拒绝
你知道我可以如何解决PHPMailer或LimeSurvey的故障,以便我可以用SMTP和TLS发送电子邮件吗 我正在使用带有phpMail 6.0.7的LimeSurvey 3.17发送带有SMTP的电子邮件,但它不工作或显示有意义的错误消息 因此,我为PHPMailer创建了一个测试php文件,并得到以下错误: 连接:打开smtp.example.com:587,超时=300, options=array()连接失败。Openssl PHPMailer/SMTP/LimeSurvey的权限被拒绝,openssl,smtp,phpmailer,smtp-auth,limesurvey,Openssl,Smtp,Phpmailer,Smtp Auth,Limesurvey,你知道我可以如何解决PHPMailer或LimeSurvey的故障,以便我可以用SMTP和TLS发送电子邮件吗 我正在使用带有phpMail 6.0.7的LimeSurvey 3.17发送带有SMTP的电子邮件,但它不工作或显示有意义的错误消息 因此,我为PHPMailer创建了一个测试php文件,并得到以下错误: 连接:打开smtp.example.com:587,超时=300, options=array()连接失败。错误#2: stream_socket_client():无法连接到smt
错误#2: stream_socket_client():无法连接到smtp.example.com:587 (权限被拒绝)[…phpmailer/src/SMTP.php第321行]
SMTP 错误:无法连接到服务器:权限被拒绝(13)
SMTP connect()失败 测试文件
<?php
require '../src/PHPMailer.php';
require '../src/SMTP.php';
require '../src/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$msg = '';
if (array_key_exists('email', $_POST)) {
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->Port = 587;
$mail->setFrom('user@example.com', 'Server Test');
$mail->addAddress('user@example.com', 'John Doe');
$mail->SMTPDebug = 4;
$mail->SMTPAuth = true;
$mail->Username = 'user@example.com';
$mail->Password = 'j83kc74,%8#ge';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
$mail->Subject = 'PHPMailer contact form';
$mail->isHTML(false);
$mail->Body = <<<EOT
Email: {$_POST['email']}
Name: {$_POST['name']}
Message: {$_POST['message']}
EOT;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
$msg = 'Sorry, something went wrong. Please try again later.';
} else {
$msg = 'Message sent! Thanks for contacting us.';
}
} else {
$msg = 'Invalid email address, message ignored.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact form</title>
</head>
<body>
<h1>Contact us</h1>
<?php if (!empty($msg)) {
echo "<h2>$msg</h2>";
} ?>
<form method="POST">
<label for="name">Name: <input type="text" name="name" id="name"></label><br>
<label for="email">Email address: <input type="email" name="email" id="email"></label><br>
<label for="message">Message: <textarea name="message" id="message" rows="8" cols="20"></textarea></label><br>
<input type="submit" value="Send">
</form>
</body>
</html>
更新1:php-i | grep-i socket
/etc/php.d/20-sockets.ini,已注册 流套接字传输=>tcp、udp、unix、udg、ssl、sslv3、tls、, tlsv1.0、tlsv1.1、tlsv1.2
mysqli.default\u socket=> /var/lib/mysql/mysql.sock=>/var/lib/mysql/mysql.sock
pdo_mysql.default_socket=>/var/lib/mysql/mysql.sock=> /var/lib/mysql/mysql.sock
sockets
sockets支持=> 已启用
默认\u套接字\u超时=>60=>60 更新2:
我可以用Grafana(仪表板软件)发送电子邮件,但我不认为它使用php和openssl。所以我猜它与http或php有关。我想知道我是否有需要更改的apache设置。
我还尝试了以下命令:
setsebool-p httpd_can_网络_连接1 更新3: Selinux被禁用,我在PHPMailer中设置了下面的值,并且我能够发送一封带有测试php文件的电子邮件。Limesurvey不工作,但至少我知道邮件会发出。
public$do_debug=debug_LOWLEVEL
看起来像是PHP配置问题-可能套接字函数已被禁用?你能检查一下你的php.ini设置吗?(在命令行上运行
php-i
)谢谢。我添加了一个更新。我想这可能是SELinux的问题-看看。谢谢。不走运。我添加了一个更新。你确定这不是其他SELinux(或者AppArmor)设置吗?需要应用策略的二进制文件可能与答案中的不完全相同,例如,您可能需要将其应用于PHP-FPM而不是apache(httpd)。尝试完全关闭SELinux;如果它起作用,你就会知道它就在那里的某个地方。此外,任何违反SELinux规则的行为都应该被记录下来,所以也要检查一下。
echo -n "\0user@example.com\0j83kc74,%8#ge" | base64
RETURNS: XDB1c2VyQGV4YW1wbGUuY29tXDBqODNrYzc0LCU4I2dl
openssl s_client -starttls smtp -crlf -connect smtp.example.com:587
EHLO there
AUTH PLAIN XDB1c2VyQGV4YW1wbGUuY29tXDBqODNrYzc0LCU4I2dl
MAIL FROM:user@example.com
RCPT TO:another_user@example.com
DATA
This is a Test. Hello World.
.
QUIT