I have a contact form on my joomla website – yet for some reason all of a sudden the emails are starting to come through with things like %22, %40, %0A instead of the symbols?
I’ve tried using htmlspecialchars_decode, and a few other options but can’t seem to get rid of them other than using str_replace, but obviously that won’t get rid of all of the characters. Can anyone help me out? I’m not sure why it’s changed all of a sudden.
Here’s my contact form:
<form name="contact" id="contact">
<div id="contactForm">
<div class="information">
<div class="__left">Name: *</div>
<div class="__right"><input type="text" name="name" id="name" class="inputbox required" /></div>
<div class="clear"></div>
</div>
<div class="information">
<div class="__left">Email: *</div>
<div class="__right"><input type="text" name="email" id="email" class="inputbox required email" /></div>
<div class="clear"></div>
</div>
<div class="information">
<div class="__left">Phone: *<br /><em>(Please include area code - XX XXXX XXXX)</em></div>
<div class="__right"><input type="text" name="phone" id="phone" class="inputbox required phone" /></div>
<div class="clear"></div>
</div>
<div class="information">
<div class="__left">Message: *</div>
<div class="__right"><textarea name="message" id="message" rows="10" class="inputbox required"></textarea></div>
<div class="clear"></div>
</div>
<div class="__right"><input type="submit" name="submit" id="submit" value="Submit" class="button" /></div>
<div class="clear"></div>
</div>
</form>
and here’s the php:
$name = htmlspecialchars_decode(JRequest::getVar('e_name'));
$email = htmlspecialchars_decode(str_replace('%40','@',JRequest::getVar('e_email')));
$phone = htmlspecialchars_decode(JRequest::getVar('e_phone'));
$body = htmlspecialchars_decode(str_replace('%0A','<br />',JRequest::getVar('e_message')));
//send an email
$emailto = $emailto;
$emailfrom = $email;
$emailfromname = $name;
$subject = $subject;
# prepare email body text
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'. $subject .'</title>
</head>
<body>
<p>'. $body .'</p>
<hr />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="300" align="left" valign="top">Name:</td>
<td align="left" valign="top">'. $name .'</td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td align="left" valign="top">Email:</td>
<td align="left" valign="top">'. $email .'</td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td align="left" valign="top">Phone:</td>
<td align="left" valign="top">'. $phone .'</td>
</tr>
</table>
</body>
</html>';
// send email
if (JUtility::sendMail($emailfrom, $emailfromname, $emailto, $subject, $message, 1, $cc, $bcc, $attachment, $replyto, $replytoname)) {
$response[] = 1;
} else {
$response[] = 0;
};
Use urlencode or urldecode
Cheers 🙂