问题描述
我正在尝试将存储在我的服务器上的图像添加到使用 PHP 的 mail() 函数发送的电子邮件中。这是下面的PHP代码:
$subject = 'Password Reset';
$message = '
<html>
<head>
<title>Password Reset</title>
</head>
<body>
Salve '.$username.',utilizza questo link per resettare la password: <a href="https://gestionale.boscarato.eu/Elaborato/reset/reset_password.PHP?c='.$operation_code.'">Resetta la tua password </a>
<br><br>
<img src="http://gestionale.boscarato.eu/Elaborato/images/logo.png" alt="logo" width="300" height="50">
<br>
Cordiali saluti,<br>
<h5>Luca Boscarato [5E] </h5>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Luca Boscarato <boscarato.luca@gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($email,$subject,$message,$headers);
问题是无法显示图像(我已经在 gmail 上激活了“全部接受”选项,以便我的客户也接受外部图像。
解决方法
将 http://
协议(在图像 URL 中)替换为 https://
。
错误是由于远程服务器配置不正确造成的。
HTTPS 正确加载
https://gestionale.boscarato.eu/Elaborato/images/logo.png # HTTPS correct
但是 HTTP 重定向到无效的 URL
http://gestionale.boscarato.eu/Elaborato/images/logo.png # HTTP before redirect
重定向到
https://gestionale.boscarato.euelaborato/images/logo.png # invalid URL
注意 .eu
TLD 后面缺少的斜线。
curl -I "http://gestionale.boscarato.eu/Elaborato/images/logo.png"
HTTP/1.1 301 Moved Permanently
Date: Fri,14 May 2021 19:21:06 GMT
Server: Apache/2.4.38 (Raspbian)
Location: https://gestionale.boscarato.euElaborato/images/logo.png
Content-Type: text/html; charset=iso-8859-1