【问题标题】:Include php mail headers in ssh2 mailing function. Sending emails in html format using ssh2在 ssh2 邮件功能中包含 php 邮件标头。使用 ssh2 以 html 格式发送电子邮件
【发布时间】:2017-07-11 00:25:28
【问题描述】:

所以我使用 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 标头吗?提前非常感谢。

【问题讨论】:

标签: php html email phpmailer ssh2-exec


【解决方案1】:

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

$command = "echo \"{$message}\" | mailx -a 'Content-Type: text/html' -s \"{$subject}\" {$to}";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2012-12-12
    • 2017-08-22
    • 1970-01-01
    • 2017-06-28
    • 2012-02-04
    • 2010-11-26
    相关资源
    最近更新 更多