php - 如何向 SMTP 脚本添加身份验证?
问题描述
我正在使用这个脚本来计算主机服务器上使用的总存储空间并发送包含详细信息的电子邮件。到目前为止,它总是与不同的服务器一起工作,但新的服务器似乎需要身份验证才能发送电子邮件。
<?php
$filePath = "./";
$total = 0;
$d = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($filePath),
RecursiveIteratorIterator::SELF_FIRST
);
foreach($d as $file){
$total += $file->getSize();
}
$to = 'test@gmail.com';
$subject = "Storage " .number_format($total/1048576, 2);
$message = "Storage " .number_format($total/1048576, 2);
$headers = "MIME-Version: 1.0\n";
$headers .="Content-Type: text/html; charset=\"ISO-8859-1\"\n";
$headers .= 'From: XYZHost <test@domain.com>' . "\r\n" .
'Reply-To: test@domain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
ini_set("SMTP", "mail.domain.com");
mail($to, $subject, $message, $headers);
?>
交付失败并出现以下错误:
Diagnostic-Code: smtp; 550-Verification failed for <account@xyz.hosting>
550-Called: ---
550-Sent: RCPT TO:<account@xyz.hosting>
550-Response: 550 5.1.1 User unknown: account@xyz.hosting
550 Invalid sender <account@xyz.hosting>
有没有办法在这里添加身份验证?
解决方案
推荐阅读
- python - 将 C 程序手动翻译为 Python - 严重错误
- javascript - 如何操作 css 动画以像 :hover 一样使用 javascript?
- android - 带电容器的离子 LocalNotifications:找不到 NotificationCompat
- unity3d - 如何增加一个数字但不是一次(使用 Unity 引擎)
- javascript - 如何使用javascript将迭代的json值捕获到变量中
- wordpress - 影响单个产品价格而不影响下面的相关产品
- azure-devops - Azure 部署组
- android - 如何在 Android 中使用 PyTorch 的 torchaudio?
- mysql - 在动态日期范围之间提取数据
- python - 循环中更新 imshow 和循环后颜色图中的问题