I use the php mail function to send a link with many parameters. The URL after encoding can be 650 or more characters because its holding variables re-fill the form.
When I click on the link in my letter, it broke because the place was inserted somewhere in the URL.
Here is my sendMail function:
protected function sendEmail($to, $subject, $body) { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n'; $headers .= 'From: Sales Order From <sales@imninjas.com>' . '\r\n'; $headers .= 'X-Mailer: PHP/' . phpversion() . '\r\n'; $body = '<html><body style="font-size: 10pt; font-family: Arial, Helvetica, sans-serif;">'.$body.'</body></html>'; return mail($to, $subject, $body, $headers); }
Here is the code I'm calling sendMail with. Its '$ salesUrl = $ this-> getSalesFormUrl ();' i.e. 650+ character set filled with encoded parameters.
function emailRep() { $params = $this->getParamaterArray(); $shortUrl = $this->getShortUrl(); $salesUrl = $this->getSalesFormUrl(); $mailSubject = "Return to the sales order form for ".$params['clientName']." at ".$params['company']."."; $mailBody = "The following information is from an order created on, ".date("l, F j, Y \a\tg:ia").",<br/><br/>"; $mailBody .= "Customer Contact Information:<br/>"; $mailBody .= "Name: ".$params['clientName'] params['company']."<br/>"; $mailBody .= "Shortened Url to Send to the Customer:<br/>"; $mailBody .= ($shortUrl) ? "<a href='".$shortUrl."'>".$shortUrl."</a><br/><br/>" : "There was an error shortening your url.<br/><br/>"; $mailBody .= "The URL back to the sales form: For sales rep use only, <strong>Do not give to the customer</strong>.:<br/>"; $mailBody .= "<span style='font-style: italic;'>Some email clients add special characters to long urls. If the link does not work then copy and paste it into your browser.</span><br/>"; $mailBody .= "<a href='".$salesUrl."'>".$salesUrl."</a><br/><br/>"; return ($this->sendEmail($params['repEmail'], $mailSubject, $mailBody)); }
And here is the URL that I get in my letter, you will see a space "... BhsNKq Jsd_x4 ..." in the middle of the URL. This happens elsewhere every time, even if I submit the same URL. To prove this, I hard-coded this url without a space in the emailRep method and sent it several times. The space was moving.
http:
Here is the code that I use to encode / decode URL parameters before sending via email.
class UrlEncoder { function compressUrl($url) { return rtrim(strtr(base64_encode(gzdeflate($url, 9)), '+/', '-_'), '='); } function uncompressUrl($url) { $startParams = strrpos($url, "?"); if($startParams) { $paramaterString = substr($url, $startParams); $host = substr($url, 0, strrpos($url, "?")); $uncompressedParamaters = gzinflate(base64_decode(strtr($paramaterString, '-_', '+/'))); return $host."?".$uncompressedParamaters; } else { return NULL; } } }
How to prevent this space? I know that I can shorten the URL with something like bit.ly, but its an internal tool. I feel that there must be a way to stop the space from pasting.