I am trying to embed an image to html when sending email.
I have the image (logo.png) and html (welcome.html.eex) located under priv
Sadly, I receive the email without the image in it.
here is the email I receive:
when I inspect element I get: (no src=" ... ")
<img width="212px" height="26px" align="bottom">
though - when I preview locally my html (from my-html.html - see in my code ) seems ok:
here is my welcome.html.eex
<p>
<span>
<strong>Bem-Vindo hii</strong> à
<img
src="<%= ~s(data:image/png;base64,) <> Base.encode64(File.read! (Path.join("#{:code.priv_dir(:my_app)}", "logo.png"))) %>"
width="212px" height="26px" align="bottom"/>
</span>
</p>
here is my code, sending email adding the html using bamboo:
import Bamboo.Email
def send_verify_email() do
File.write "my-html.html", get_html() # writing the html localy - to verify..
new_email()
|> to("foo#bar.com")
|> from(#from_addr)
|> subject("Welcome")
|> html_body(get_html())
|> Mailer.deliver_later
end
end
def get_html() do
EEx.eval_file(Path.join("#{:code.priv_dir(:my_app)}", "welcome.html.eex"), [tok: "123"])
end
what am I doing wrong?
how can I attach a base 64 image on email html?
edit
I also tried adding image by path
welcome.html.eex
<img src="<%= Path.join("#{:code.priv_dir(:my_app)}", "logo.png") %>"
but still get same results - locally html seems ok, but on email html is:
when I inspect I get
<img src="https://ci4.googleusercontent.com/proxy/4eMU8Te6MM215JLJ5gm3Z9jnC4hytOkDeF4ldFGb1pC17GDhtZphCtH623p1ZwNYZxBfAatQtlX_V9MKALbOE0jIzxVXJ43tZLeA5hUT7tjs7FEz3_PVoUQ5Ih7w0rvuRtLy7pVqR9UoU5TBF5E=s0-d-e1-ft#http:///home/dina/Documents/WK/my_umbrela_app/_build/dev/lib/my_app/priv/logo.png" width="212px" height="26px" align="bottom" class="CToWUd">
so I do have src="" but it seems broken.. :(
Example:
<a title="A web design community.'test'~`!##$%^&*()-_+=\|][{};:,<.>?/ **"new test"** " href="http://css-tricks.com">CSS-Tricks</a>
In tooltip, after the double quotes "new test" is not working.
Is there any possible to show the content in tooltip like this
ex: testing 'welcome', # 3 $ ^ & * "flow"?
The problem is that your double quotes in the title close your title automatically. Escape them by replacing " with " and also funkwurm recommends to replace < and > with < and > respectively to avoid errors in xml:
<a title="A web design community.'test'~`!##$%^&*()-_+=\|][{};:,<.>?/ **"new test"** " href="http://css-tricks.com">CSS-Tricks</a>
You can use this is also.
<a title="Answer to your's question.'Test It' :):)'B Happy' :):)"new test"**" href="http://css-tricks.com">CSS-Tricks</a>
I have the following code inside my asp.net MVC view:-
<img class="thumbnailimag" src="~/Content/uploads/#item.ID.ToString()" + ".png" />
but I am unable to concatenate the .png to my href & src . can anyone advice please ?
Thanks
You'll want to wrap the code in parentheses, as explained here. No need to call .ToString() then:
href="~/Content/uploads/#(item.ID).png"
Your quotes are not closed properly.
href='#string.Format("~/Content/uploads/{0}.png", item.ID)'
Complete Code
<a href='#string.Format("~/Content/uploads/{0}.png", item.ID)'><img class="thumbnailimag" src='#string.Format("~/Content/uploads/{0}.png", item.ID)' /></a>
Alternatively, declare fileName outside of the href (IMO makes it more readable)
#{
var fileName = item.ID.ToString() + ".png";
}
<img class="thumbnailimag" src="~/Content/uploads/#fileName" />
I know how to use the smarty mailto function to create mailto anchor links with encoding. But I am wondering if it is possible for example to insert html image tags [<img>] into the output of this function.
I have tried:
[SMARTY]
{$text = '<img src="/images/qr_code.jpg" alt="member sign up qr code">'}
{mailto address="test#example.com" encode="hex" text={$text}}
[HTML RESULT]
<a href="mailto:%74%65%73%74#%65%78%61%6d%70%6c%65.%63%6f%6d">
<img src="/images/qr_code.jpg"
alt="member sign up qr code" >
</a>
I am after this output rather:
<a href="mailto:%74%65%73%74#%65%78%61%6d%70%6c%65.%63%6f%6d">
<img src="/images/qr_code.jpg"
alt="member sign up qr code">
</a>
It seems, from reading this code https://bitbucket.org/pferor/dbless/src/04b228943e39/dbless/lib/smarty/plugins/function.mailto.php, that when you use the "hex" encoding it not only encodes the address but also the text (line 147):
$text_encode = '';
for ($x=0; $x < strlen($text); $x++) {
$text_encode .= '&#x' . bin2hex($text[$x]).';';
}
Not sure if that's the problem though.
If you don't mind editing the Smarty source youmight be able to change this line (153):
return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text_encode.'</a>';
To this:
return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text.'</a>';
To make it work.
If you try "none" encoding does it show the image then?
it has always been my practice that when ever i use images i name them like
walls_ico , bu_hover
so when i give paths they go like
<img src="images/walls_ico.ico" />
<img src="buttons/bu_hover.png" />
UNTIL now when i am on a project where users upload files...
i was wondering is it okay to have spaces between file and folders name like
<img src="buttons/bu hover.png" />
The src attribute should contain a valid URL. Since space characters are not allowed in URLs, you have to encode them.
You can write:
<img src="buttons/bu%20hover.png" />
But not:
<img src="buttons/bu+hover.png" />
Because, as DavidRR rightfully points out in his comment, encoding space characters as + is only valid in the query string portion of an URL, not in the path itself.
Quoting HTML5 to back Frederic that spaces are not allowed:
http://www.w3.org/TR/html5/links.html#attr-hyperlink-href:
The href attribute on a and area elements must have a value that is a valid URL potentially surrounded by spaces.
The definition of "valid URL" points to: http://url.spec.whatwg.org which defines URL code points https://url.spec.whatwg.org/#url-code-points:
The URL code points are ASCII alphanumeric, "!", "$", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "=", "?", "#", "_", "~", and code points in the ranges U+00A0 to U+D7FF, U+E000 to U+FDCF, U+FDF0 to U+FFFD, U+10000 to U+1FFFD, U+20000 to U+2FFFD, U+30000 to U+3FFFD, U+40000 to U+4FFFD, U+50000 to U+5FFFD, U+60000 to U+6FFFD, U+70000 to U+7FFFD, U+80000 to U+8FFFD, U+90000 to U+9FFFD, U+A0000 to U+AFFFD, U+B0000 to U+BFFFD, U+C0000 to U+CFFFD, U+D0000 to U+DFFFD, U+E1000 to U+EFFFD, U+F0000 to U+FFFFD, U+100000 to U+10FFFD.
The spec then uses the term URL code points on various parts of the parsing algorithm as:
If c is not the EOF code point, not a URL code point, and not "%", parse error.
for the scheme, authority, relative path, query state and fragment states: so the entire URL.
If you are using PHP
then find out this code
$result = mysqli_query($con,$sql);
//echo $ip."<br />";REGEXP
//echo $name."<br />";
echo "<table border=2px style='border-radius=20px;' align=center><tr>
<th>Document ID</th>
<th>Document Name Type</th>
<th>Download Documents</th>
</tr>";//<th>Project Document Type</th>
while($row = mysqli_fetch_array($result)) {
$path1=$row['FOLDERNAME'] .'/'. $row['FILENAME'] .'.'. $row['DOCTYPE'];
$path=str_replace(" ", '%20', $path1);
echo "<tr>";
echo "<td>" . $row['DocID'] . "</td>";
// echo "<td>" . $row['PROJDOCTYPE'] . "</td>";Thank you. Your Apple ID is now ready for use.
echo "<td>" . $row['DOCNAME'] . "</td>";
echo '<td><a href=Tender/'.$path.'>'.$row['DOCNAME'].'</a></td>';
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
<body>
<img src="file:///C|/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg"
</body>
spaces will be allowed only when you are working in local hosts