The first problem is that you're using
while read $var. That's wrong syntax since
$var means "the value of the variable var". What you want is
while read var instead. Then, variables are only expanded inside double quotes, not single ones, and you're trying to deal with that but in a needlessly complex way. You're also hard-coding the file name which is usually not a good idea. Finally, as a matter of style, try to avoid UUoC. Putting all this together, you can do:
## The -r ensures the line is read literally, without
## treating backslashes specially, so without expanding
## things like `\t`.
while read -r line;
## By putting the whole thing in double quotes, we
## ensure that variables are expanded and by escaping
## the $ in the 1st var, we avoid its expansion.
echo "or ('\$h_subject:' contains '$line')"
done < "$file"
Note that it's generally better to use
printf instead of
echo. And, in this case, it even makes things simpler since you can replace the
echo above with:
printf 'or ("$h_subject:" contains "%s")\n' "$line"
Save this as
foo.sh. make it executable and run it with the file as an argument: