Linux Mail Adding Content Type Headers Not Working

linux mail adding content type headers not working

Try

echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" foo@example.com

How to send HTML email using linux command line

Force Content Type with sendmail

I have a non solution, instead of to force my mail to be in text/plain, I will send a mail in text/html but I will add the <pre> tag to open and close my output file... And because it's now in text/html, the <pre> tag is not displayed as <pre>

It's not what I excepted but it works. So my previous script simply become:

#!/bin/bash

SENDMAIL_BIN='/usr/sbin/sendmail'
FROM_MAIL_ADDRESS='noreply@plop.com'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='me@plop.com'

MAIL_CMD="$SENDMAIL_BIN -f $FROM_MAIL_ADDRESS -F \"$FROM_MAIL_DISLAY\" $RECIPIENT_ADDRESSES"
(echo "Subject: Test format";echo -e "MIME-Version: 1.0\nContent-Type: text/html;\n" && echo '<pre>' && cat output.txt && echo '</pre>') | eval $MAIL_CMD

Why Headers Preventing mail from sending?

The sender information should be inside the headers

Hence, please change the following lines:

 $headers =
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=UTF-8";

if(mail($receiver, $subject, $email_template, $sender, $headers))

to

$sender = "iusername@host.com";

$headers = "From: $sender <$sender>\r\nReply-To: $sender\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";

if(mail($receiver, $subject, $email_template, $headers))


Related Topics



Leave a reply



Submit