0

So I am sending emails using 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);}?>

But the problem is that when I send html message it does not get sent as html compared when I send it using php mail() function. I know that's because of the headers.

$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);    

Any idea how to include the html headers in my mailitnow function? Thanks a lot in advance.

J.Cole
  • 3
  • 1
  • Possible duplicate of [Mailx send html message](https://stackoverflow.com/questions/24010230/mailx-send-html-message) – Synchro Jul 11 '17 at 09:31

1 Answers1

0

You can append message headers with the -a option to the mailx command, like this:

$command = "echo \"{$message}\" | mailx -a 'Content-Type: text/html' -s \"{$subject}\" {$to}";
Synchro
  • 35,538
  • 15
  • 81
  • 104