0

所以我使用 ssh2 发送电子邮件

<?phpfunction Mailitnow($message, $subject, $to) {
include('Net/SSH2.php');
$ssh = new Net_SSH2('my_linux_address');
if (!$ssh->login('user', 'password')) {
    exit('Login Failed');
}
$command = "echo \"{$message}\" | mailx -s \"{$subject}\" {$to}";
$ssh->exec($command);}?>

但问题是,当我发送 html 消息时,与使用 php mail() 函数发送消息相比,它不会以 html 格式发送。我知道这是因为标题。

$subject = "Test";

$message = "<html><head>
<title>Test</title>
</head><body><p>hello awesome person. please click the link</p> 
<p><a href='https://stackoverflow.com'>Continue to website...</a></p>   
<p>Thanks </p>
</body>
</html>
";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Mailitnow($message, $subject, $to);
mail($to, $subject, $message, $headers);    

知道如何在我的 mailitnow 函数中包含 html 标头吗?提前非常感谢。

4

1 回答 1

0

-a您可以将带有选项的消息头附加到mailx命令中,如下所示:

$command = "echo \"{$message}\" | mailx -a 'Content-Type: text/html' -s \"{$subject}\" {$to}";
于 2017-07-11T09:31:28.360 回答