试图让 Mailhog 运行。我正在运行一个Neard堆栈,我之前没有使用过 Mailhog。对于不熟悉电子邮件服务的人(指责自己),文档很薄。这是我在代码方面的内容:
// create the instance
$mail = new PHPMailer;
$mail->isSMTP(); // i read somwhere that this may require commenting out to work...
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = 'mail'; // i also tried 'localhost' here... same result
$mail->Port = 1025;
$mail->SMTPAuth = true;
$mail->Username = EMAILUSERNAME;
$mail->Password = EMAILPASSWORD;
$mail->setFrom($from, $senderName);
$mail->addReplyTo('blorp@blorp.blorp'); // obviously a placeholder
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML(file_get_contents(__DIR__.'\90days.php'));
// send the email and check for errors
if (!$mail->send()) {
echo 'Mail error: '. $mail->ErrorInfo;
} else {
echo 'Message sent Successfully';
}
通过Postman运行它,我收到以下错误:
2020-04-15 01:53:50 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mail error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
根据我从这篇文章中了解到的情况,我所要做的就是将Host
andPort
设置为上面的设置,Mailhog 会拦截。但它不起作用。那么我忽略或错误配置了什么?