How to prevent GMail from converting text to URL? - php

I have a small issue with GMail. My company has a ".fr" part in its name, and when we send newletters, GMail shows it as an internet adress and autmatically adds a link to it.
That's not what I want.
I found a very good solution here, and it works like a charm when I manually edit the HTML file. The magic is to add a character GMail does not know, like ­, so that is does not transform the text into a link.
The problem is when I try to automate this replacement :
$body = str_replace('my company.fr', "my company­.fr", $body);
PHP does not seem to see this ­ character, and for the little story, neither does Google...
Do you know of a way to achieve my goal, that is not having a link on my company name ?
I could do the second option in the above mentioned article, but that, to my opinion, would be my last option.
Thanks for your replies !

You can need ' not " for this special char
$body = "my company.fr"
$body = str_replace('my company.fr', 'my company­.fr', $body);
//result is my company­.fr
And using html_entity_decode for back
$st = "my company­.fr"
$st = html_entity_decode($st);
//result is my company.fr
Hope this help!

Related

html entity/specialcharacters decode

I have a question about html decode.
I'm using WordPress' gravityforms plugin to manage forms. The formtitle includes the name of the website.
This week there was a bug in the special characters, the & sign was showing in the mailbox as & . I fixed this using html specialcharacters decode which was working great.
Later it appeared that there was a similar bug with the ' sign. Apparently html_specialcharacersdecode doesn't work with that one so I tried html_entities_decode as well, which also doesn't work for the ' sign.
Other signs are decoded perfectly such as < > () : -=+ so I don't really know what the problem is. I just want the ' to show as ' and not as '.
My code:
function before_email( $email ) {
$subject = htmlspecialchars_decode($email['subject']);
$subject = html_entity_decode($subject);
$email['subject'] = '$subject';
return $email;
}
My concrete question is: Is there something I'm missing here? Like maybe some function similar to the ones I've tried or is there something else going wrong?
Thanks!
You can use,
$subject = html_entity_decode($subject, ENT_QUOTES);
However, I would advise against HTML encoding before you insert it into the database. Just encode it when you output it. It's better just storing the raw data in the database.

php mail html format link remains inactive

I wanted to make a mail function in php to let visitors create and activate a user account. For this I made a mail with a link which refers to the page that activates the account. Now the problem is that some people want to use characters that interfere with the code inside the email. for example: " " and ' '. I tried to escape these characters, but when such character appears, the link becomes inactive. The mail is sent, but the link is unclickable.
This is what the code looks like.
The variables are set in PHP
$New_user->Username = $db->real_escape_string($_POST['un']);
$RawUn = $_POST['un'];
$New_user->Password = $_POST['pw'];
$New_user->Email = $_POST['em'];
$CheckEmail = explode("#", $New_user->Email);
$New_user->Country = $_POST['cn'];
$New_user->City = $_POST['ct'];
//$NEW_USER IS AN OBJECT CREATED TO HOLD ACCOUNT INFORMATION SUCH AS USERNAME AND EMAIL
//$RAWUN IS A VARIABLE TO HAVE AN UNESCAPED VALUE OF THE USERNAME TO INSERT IN THE INPUT FIELD IF SOMETHING WENT WRONG
After checking the values, the mail is sent:
$message = array(
'Hello ' . $New_user->Username . ',<br/>',
'<br/>',
'Welcome to MakeAMemo.<br/>',
'To start working with your account you will have to activate it.<br/>',
'Just click on the link and you are ready to go.<br/>',
'Log in and check if it works. If not, please contact us(E-mail is on the website).<br/>',
'Your password: ' . $New_user->Password . '<br/>',
'<br/>',
'Kind regards,<br/>',
'<br/>',
'Administration');
$header = array(
'From: makeamemoofficial#gmail.com',
'Reply-To: makeamemoofficial#gmail.com',
'Content-type: text/html');
mail($New_user->Email,"MakeAMemo => New account",implode("\r\n", $message),implode("\r\n", $header));
I have made a connection to the datebase, so the escaping using $db->real_escape_string works fine.
The location of the link will be changed when the website is finished.
I checked if the code worked without the str_replace in the href. No succes. Neither I got succes trying to not escape the username.
The tags are invisible in the mail, so it is recognised. The link is not blocked, because it does work when I don't use special characters. When changing the double quotation marks into single quotation marks, you reverse the effect, which means that instead of " ", ' ' don't work.
I do not think the headers have something to do with it, because the link does work when using normal characters.
Any idea what the cause of my problem is?
Every answer is appreciated.
adear11: here is the generated tag:
link
"s avonds is an incorrect dutch word that contains some of the characters that need to be tested.
Rather than using str_replace in your email, you should use urlencode http://php.net/urlencode
This function is specifically for encoding strings for use in urls
As for the link not always working when it is formed properly, would be that the user isn't using HTML email.
Also, while not specific to your problem, this script is crazy insecure. You never ever ever need to use user supplied input ($_POST in your case) without sanitizing the input first. At a minimum, all of those assignments need to be run through htmlspecialchars.
Update
Given the trouble that you are having, I would consider not passing the actual data around in the URL. Rather, I would save the data to the DB and then generate a token to put in the url. If you generate a token with uniqid you won't have any trouble with these special characters because the string will be alphanumeric. Once the user clicks the link, just grab the data associated with the token and proceed as you would if the data was in the URL.

Passing HTML entities through URL

I am trying to pass the Euro symbol i.e "€" and the "#" symbol, but they are not working, the euro symbol is looking like "€" and the "#" symbol is looking like "%40", I am using "urlencode()" function in PHP, but it doesn't seem to work, please let me know what could be wrong.
P.S I am transferring data from GET to another page then sending it in email, in email it is looking like the above.
EDIT: This is page 1:
$temps=urlencode($temps);
header('Location:http://someurl.com/mailx.php?data='.$temps);
This is page 2: Here I am emailing the data.
$mailmsg = $_GET['data'];
Output seen in my email inbox:
Email: name%40gmail.com
Notice that %40 instead of "#"?
You need urldecode(), read more here.
$var = "name%40gmail.com";
echo urldecode($var);
//output name#gmail.com

mailto php removing new line characters

I'm using a mailto link to send e-mail with a php string variable inside it as follows:
'Would you like to E-mail stakeholders? <a class="emailLink" href="mailto:stakeholders?subject=Alert '.$ticket.'&body=Experience: %0D%0A'.$exp.'">Review and Send!</a><br><br>';
I discovered that in the e-mail client it prints it out like:
Experience:
Th Experience should contain:\r\n\r\nImpact\r\nHow to replicate\r\nComprehensive notes
So I tried:
$charactersToRemove = array("\r\n","\n","\r");
$replaceWith = "%0D%0A";
$exp = str_replace($charactersToRemove,$replaceWith,$exp);
Which doesn't seem to make a difference...Can someone tell me why? Thanks.
Can you post more of your code to show how $exp was assigned it's value?
I've edited out my answer until I can provide better help.
EDIT: Can you seriously try using "\r\n" with \" to escape "'s instead, just in case PHP is somehow localizing %0D$0A in your HTML output? What does the source of your page look like?

How to parse a variable?

I have the following test line in my PHP which works fine as a way of posting to Twitter from within my PHP code.
$oauth->post('statuses/update', array('status' => "hello world"));
However I want to post the contents of a variable as opposed to Hello World
If I change the code as follows, then all that gets posted is $message
$oauth->post('statuses/update', array('status' => '$message'));
I also tried without the ' but then nothing got posted, ie
$oauth->post('statuses/update', array('status' => $message));
How can I correctly parse the contents of $message?
$message is created as follows
$message = "http://www.smartphonesoft.com/index.php?option=com_mtree&task=viewlink&link_id=" .$link_id . " " ."Windows Phone Software" . " " .$link_name . " " . $metadesc;
I added an echo $message which showed me what I expected, namely:
http://www.smartphonesoft.com/index.php?option=com_mtree&task=viewlink&link_id=33183073
Windows Phone Software Pocket Player
Pocket Player is a rockin' way to
enjoy music and video on your Windows
Mobile device. Through multiple media
and playlist formats, Internet
connectivity, plugin extensions, and
an intuitive interface, Pocket Player
means less taps, more music!
Thanks,
Greg
From the Twitter API doc for status/update:
status The text of your status update, up to 140 characters. URL encode as necessary.
So I'd say you have to shorten the $message, because yours has 369 characters.
The last code you quote is correct. Are you sure $message has meaningful content?
(Aside: The reason for '$message' posting "$message" verbatim is that single-quoted strings in PHP do not get variable interpolation nor escape characters: '\n' is literally "\n", whereas "\n" would result in a string containing the newline character.)
'$message' can't work because you're actually passing the string "'$message'", and not the $message variable.
If the second code you posted doesn't work, it's either because $message is not defined in your script, or because something else in your script is wrong, but we can't really tell that without seeing the rest of the code.
Since your URL is way too long for twitter, perhaps you'd like to shorten the url before posting it.
The bit.ly API documentation page will help you set up an account and your own api key.
You could then either devise your own code from the official documentation or follow this bit.ly api tutorial by David Walsh

Categories