Android Question Email verification link getting corrupted

james_sgp

Active Member
Licensed User
Longtime User
Hi, I`m doing a user registration in an SQL database through PHP. It works perfectly, but I`m sending a verification link with B4A and the url is getting corrupted for some reason.

http://www.XXXXXXX/XXXXXXX/register2.php?Action=Mail&cardid�9290041B1CED2A6297828077BC7FD9ADDDE05A17BED25D5889F55F658BA14B
http://www.XXXXXXX/XXXXXXX/register2.php?Action=Mail&cardid|31FCF629ED596B4447AE6141772AE1CCB0374EE7A8A6D9FE1AF7C7DB2A9241
http://www.XXXXXXX/XXXXXXX/register2.php?Action=Mail&cardid�6B8C72ABBBECA798070C8CC198C5BAAF7AA012D83B4EA8EDEE3101653A35E2

The = after cardid is getting lost/changed, as I`m losing the first 2 characters of the code. It happens when reading on Outlook on PC, and on Yahoo webmail.

B4X:
Dim my_msg As String
SMTP1.To.Add(XXXXXXXX)
SMTP1.Subject = XXXXXXX
My_msg = .....
my_msg = my_msg & EncDec.AESEncrypt(XXXXXXXX)                   
SMTP1.Body = my_msg
SMTP1.Send

This is one of the strings I`m sending, via SMTP
http://www.XXXXXXX/XXXXXXX/register2.php?Action=Mail&cardid=AA9290041B1CED2A6297828077BC7FD9ADDDE05A17BED25D5889F55F658BA14B
 

JohnC

Expert
Licensed User
Longtime User
Try adding this line somewhere before the SMTP1.Send line:
B4X:
SMTP1.HtmlBody = True
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
And if that doesn't work, then still keep the .HtmlBody=True line in the code but then use an <A> tag for the link instead of your long plain text link:
B4X:
<a href="https://[yourlonglink]">Click to Verify</a>

(you might also need to put the entire email body text in a "<HTML><BODY>......[your email message]......</BODY></HTML>" wrapper)
 
Last edited:
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
I tried adding HTMLbody and converting the message to full HTML, and also changed to StringBuilder (out of desperation); but to no avail, I still get the same problem with the link being corrupted when sown. Whether the HTML tags etc are in the message the link is still shown as a hyperlink by both email software, which is making my wonder....

Some more troubleshooting on the problem, if I remove the = after cardid then the reference string does not get the first 2 characters cut off. So it would appear that there is some issue being caused by the =. Has anyone else come across this?
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
But if you put the link inside an <A> tag as in my "Click to Verify" example in post #3, then you shouldn't see the actual http://xxx link, you should only be able to see "Click to Verify".

If you still see the http://xxxx link when using the <A> tag, then something is not formatting the email body properly as HTML.
 
Last edited:
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Of course...your don`t see the link, but when I click on it the URL given is the mal-formed version as before (i.e. there is no change).
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Further troubleshooting info, so I tried a shorter URL manually types (not built using variables), the result in the email message is again changed but not the = is changed to a %?

Code = http://XXXXX/register2.php?id=1234
RESULT = http://XXXXX/register2.php?id34

Something fundamentally going wrong here, why can`t I send a parameterized URL in an email from my mobile; I`m sending via Gmail, and I just tried sending the same URL to myself from and to Yahoo mail and everything was fine.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Of course...your don`t see the link, but when I click on it the URL given is the mal-formed version as before (i.e. there is no change).
Now I understand you.

I think this has to do with encoding - Try formatting the html code like this:
B4X:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>

<a href="https://[yourlonglink]">Click to Verify</a>

</body>
</html>
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
If that doesn't work then change the meta tag to this:
B4X:
<meta charset="ISO-8859-1">
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
JohnC,
Good suggestion but no luck...

And some more info, if I read the email in RoundCube the = is removed (not replaced with anything).
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, just to make sure we are on the same page....you tried BOTH meta tags (in my full HTML code in post #9) and then changing just the meta to post #11?

I ask because if there is any mis-communication, we will go on a wild goose chase ;)
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
drgottjr,

Using StringUtils to encode the url, gives me an unusable URL:
<p><a href=http%3A%2F%2Fwww.XXXXXX%2FXXXXXXX%2Fregister2.php%3FAction%3DMail%26cardid%3DAA9290041B1CED2A6297828077BC7FD9ADDDE05A17BED25D5889F55F658BA14B target='_blank' rel='noopener'>CLICK HERE TO VERIFY</a></p>
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
JohnC,

Yes, I have tried both utf-8 & ISO-8859-1, but don`t see any difference; still have ethe same error.

?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, change the email body to this (so it will remove the header tag):
B4X:
<!DOCTYPE html>
<html lang="en">
<body>

<a href="https://[yourlonglink]">Click to Verify</a>

</body>
</html>

Then add these lines before the SMTP1.Send:
B4X:
Dim M as Map
M.Initialize
M.Put("Content-Type", "text/html; charset=utf-8")
SMTP1.AdditionalHeaders = M
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Sigh....sorry to say the same thing, no change.

Am I doing something unusual in B4A, do other people send verification messages from B4A?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
If that doesn't work, then change the one line to:
B4X:
M.Put("Content-Type", "text/html; charset=ISO-8859-1")
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
If that doesn't work, then try this...

Get an email that WORKED, then do a "View Source" and copy and paste the html code in that email into your B4A code and set that code to the ".Body" and try sending the email again. So, in effect we are just simply re-sending known good HTML code.

If it then works, then you know it is something in the html source that is the key to getting this working and you'll just have to reduce it more and more to narrow down to what the "fix" is.

If it doesn't work, then compare the "View Source" of the bad email to the good email and see what the difference is.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Just to confirm, this is what I`m sending:
register2.php?Action=Mail&cardid=DE6B8C72ABBBECA798070C8CC198C5BAAF7AA012D83B4EA8EDEE3101653A35E2

This is the URL I`m getting in the email:
register2.php?Action=Mail&cardid%EF%BF%BD6B8C72ABBBECA798070C8CC198C5BAAF7AA012D83B4EA8EDEE3101653A35E2
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Is the line starting with "%EF" on a separate line because this forum software is doing the wrap or is it wrapped in the email?

Also, why are there now "%" in the URL? I would change the URL back to the original way with the "=" sign in it because to me the "=" is appropriate for what you are trying to do.
 
Upvote 0
Top