简体   繁体   English

Sendmail bash 脚本,用新行连接字符串

[英]Sendmail bash script, concatenate strings with new line

I am concatenating xmsg and links to new variable body .我正在连接xmsg和指向新变量body links What I am trying to accomplish is when email send out.我想要完成的是发送电子邮件时。 I want new line between xmsg and `links我想要xmsg和 `links 之间的新行

xmail="sendmail"

links="<a href="https://www.xxx>Unsubscribe</a>"
xmsg='Hello World'
body=$xmsg \n $links

### Compose emails one at a time, per loop.
"$xmail" "$email" << EOF
subject:$xsub
from:$xfrom
Content-Type: text/html;
Mime-version:1.0;
$body
EOF

Excepted output in email电子邮件中的异常输出

Hello World
Unsubscribe

I tried almost everything here .在这里尝试了几乎所有的方法。 But none works, either I get blank body in email or all in same line但没有任何效果,要么我在电子邮件中得到空白正文,要么全部在同一行

You're sending an HTML email and need to use <br> instead of \\n .您正在发送 HTML 电子邮件,需要使用<br>而不是\\n

You need to enclose the whole string in double quotes.您需要用双引号将整个字符串括起来。 Try body="$xmsg <br> $links"试试body="$xmsg <br> $links"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM