dombrorj Posted February 2, 2011 Share Posted February 2, 2011 Hi, I'm trying to do the following: $name = $_GET['thename']; $to = "[email protected]"; $subject = "Subject of Email"; $message = "Click this link: http://mysite.com?$name" $headers = "From: Me" . "\r\n" . "Reply-To: [email protected]" . "\r\n" . "X-Mailer: PHP/" . phpversion(); mail($to, $subject, $message, $headers); The problem I'm experiencing is that the Get function retrieves "/thename=First+Last name", which converts to a broken link in the message (because of the "+" in the url). How would I use urlencode to make sure the Get replaces the + with a %20 in this instance? It doesn't seem that I can use php in the message itself. Thanks! Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/ Share on other sites More sharing options...
ChemicalBliss Posted February 2, 2011 Share Posted February 2, 2011 You need to use concatenation, but also the variable should only be the actual value of the get request item; $name = $_GET['thename']; // gets First+Last name $to = "[email protected]"; $subject = "Subject of Email"; $message = "Click this link: http://mysite.com?/thename=".urlencode($name); hope this helps Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169115 Share on other sites More sharing options...
dombrorj Posted February 2, 2011 Author Share Posted February 2, 2011 Thanks for the help! I should have been more clear though on the message part, because there's more text after the link. I'ts more like: Click this link http://mysite.com?/thename=$name&var=$var2 more text... more text... Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169123 Share on other sites More sharing options...
ChemicalBliss Posted February 2, 2011 Share Posted February 2, 2011 then since your making the variable _knowing_ that it is going to be used in a url (since it is formated for a header request), the values should be urlencoded() at the point of the strings creation. Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169131 Share on other sites More sharing options...
dombrorj Posted February 2, 2011 Author Share Posted February 2, 2011 Hmmm... I wish I could do that but the values are passed by my merchant processor. Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169134 Share on other sites More sharing options...
ChemicalBliss Posted February 3, 2011 Share Posted February 3, 2011 Then you will need to split the variable itnto its different parts. Can you confirm that this is what you get (Exactly)? /thename=First+Last name and not /?thename=First+Last name Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169146 Share on other sites More sharing options...
dombrorj Posted February 3, 2011 Author Share Posted February 3, 2011 Thanks for all the help with this ChemicalBliss. The URL with the variables I want to Get is: /order-confirmation.php?item=136&reciept=6BB4B95E&thename=Dave+Test&cemail=test%40test.com&country=US&zip=90210 Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169154 Share on other sites More sharing options...
dombrorj Posted February 3, 2011 Author Share Posted February 3, 2011 Got it... man I need to get past this learning curve! Just needed to add: $custname: urlencode($name); Then change all the $name instances to $custname. Thanks again for all your help! Link to comment https://forums.phpfreaks.com/topic/226507-php-mail-with-urlencode-in-the-message/#findComment-1169180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.