Forum Moderators: phranque

Message Too Old, No Replies

Sendmail: linking to an image

         

csdude55

3:00 am on Dec 5, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't use sendmail a lot, and I can't quite remember how to make this work right. I'm trying to send an email to an admin when a user submits a form, and I want to link to an image if they submitted one.

But in Outlook, the link is removing the first 2 characters of the link. So when I send:

<img src="https://www.example.com/image.jpg">

Outlook is getting:

<img src=ttps://www.example.com/image.jpg">

But it works fine in Thunderbird.

I'm coding in Perl, but I put it here because I think it's really a sendmail question:

 # set $mailprog, $username, $subject, and $boundary
$img = "<img src='https://www.example.com/$pic'>";

open(MAIL,"|$mailprog -t");
print MAIL <<EOF;
To: admin\@example.com
From: $username
Subject: $subject
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="$boundary"

This is a multi-part message in MIME format.

--$boundary
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

(blah blah blah)

--$boundary
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">

<font face=Arial>
(blah blah blah)

$img
</font>

--$boundary--

EOF
close MAIL;


I have the same problem if I change the <img src...> tag to <a href...>. The problem is always following the =.

What's the correct way to code this?

phranque

4:14 am on Dec 5, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



perhaps outlook is trying to remove images and it gets munged in the process.

you might try embedding a base64 encoded image in the body of the email and modify the src to appropriately refer to that image.

phranque

4:17 am on Dec 5, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



this is merely a shot in the dark, but try using the qq quoting operator and double quotes for the attribute value to see if that fixes anything:
$img = qq(<img src="https://www.example.com/$pic">);

csdude55

9:06 pm on Dec 5, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, it looks like the problem is any link, not just an image link :-( The <a href...> link is messing up, too. So this:

<a href="https://www.example.com/view.php?id=csdude">https://www.example.com/view.php?id=csdude</a>

becomes:

<a href=ttps://www.example.com/view.php?id=dude">https://www.example.com/view.php?id=dude</a>

(removing the next 2 digits after both equal signs)

The code I'm using here, based on your suggestion with qq():

use URI::Escape;

$uri_user = uri_escape($username);
$link = qq($home/view.php?id=$uri_user);

lucy24

11:04 pm on Dec 5, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just for ### and giggles: What happens if you sneak in a couple of extra spaces--or, I guess, a couple of non-space characters--between the = sign and the "http ? (And, I guess, slip in two bogus leading characters at the front of each parameter value.)

Something is niggling at the edge of my mind and I'm trying to lure it in closer.

phranque

11:15 pm on Dec 5, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Well, it looks like the problem is any link, not just an image link :-( The <a href...> link is messing up,

indeed i forgot you had mentioned that.

csdude55

1:28 am on Dec 6, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just for ### and giggles: What happens if you sneak in a couple of extra spaces--or, I guess, a couple of non-space characters--between the = sign and the "http ? (And, I guess, slip in two bogus leading characters at the front of each parameter value.)

Well, then it would break on my Thunderbird! LOL And it currently seems to work fine on both iPhone and Android's email, so I guess that adding characters would make it break on those, too.

This seems to only be a problem for Outlook, but I can't find any reference to it anywhere else. The admin is specifically using Outlook 2007, if that helps?

csdude55

1:37 am on Dec 6, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Wait, I think I found it! The problem is here:

Content-Transfer-Encoding: quoted-printable


QP works by using the equals sign = as an escape character... an ASCII equal sign (decimal value 61) must be represented by =3D


[en.wikipedia.org...]

So it looks like changing all of the = to =3D should work (in theory, I haven't tested it). What's the preferred Content-Transfer-Encoding for email, though, if not "quoted-printable"?

phranque

2:37 am on Dec 6, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i thought it might be related to encoding - still don't understand why it would try to decode something that wasn't hexadecimal digits.