Hi,
I am having trouble communicating my problem. I have a contact form - and below is the code that processes the data from the contact form. It emails the data from the contact form to an email address that has previously been encoded. So before I ever write this php mailer code, I have to know which web site I'm working on and use some other php code to encode the email address - see the code labeled: PHP Mailer to see how this works - the comments explain. In my made up example, the coded email address string has the value 'j#asa&2lka1293-27lakmckja*uerq'. This string which will exist in a php file, can not (easily) be interpreted by bots because it's not a email address, it's encoded.
The function below labeled: Encode is 'supposed' to encode an email address passed to it. The problem is - if I test the output it's not really encoded, it's the same value I passed in. So for example if I pass in 'billyg@msn.com' - then the output should be some weird encoded string, kind of like my example above, that IS NOT an email address and does not have the '@' character in it. The output of the function is the same as what was passed into it, so it doesn't work.
Any idea why the function encode_address isn't working ? - Please if you offer suggestions, remember it has to work with the decode function. These ARE NOT run together... they're not run at the same time. If you read above, they're run at totally separate times, however whatever string I encode with the encode_address has to be able to be decoded with the decode_address function
Any help is GREATLY appreciated!!
Thanks
Vmusic
PHP Mailer
if( ($emailaddy != "") && ($fname != "") && ($lname != "") && (isset($emailaddy)) && (isset($fname)) && (isset($lname)) ){
//we're processing a submitted form
$mail_to = "j#asa&2lka1293-27lakmckja*uerq"; //no bots understand this
$mail_from = $emailaddy;
$mail_subject = "Web Site Inquiry";
$mail_body = "This email comes from the contact form on the XYZ Web Site\n\n";
$mail_body .= "It is from: " . $fname . " " . $lname . "\n\n";
$mail_body .= "Their return email is: " . $mail_from . "\n\n";
$mail_body .= "Their message is: \n" . stripslashes($msg);
$mail_to = decode_addr($mail_to); //now I'll decode it in memory
//mail it
if(! mail($mail_to, $mail_subject, $mail_body, "From:$mail_from")){
//set the thanks message for an error
$txt_welcome = " There was an error sending your inquiry. The webmaster has been notified. <br><br><br>Thanks!!\n";
.... more code here etc.
Encode
function encode_address($addr)
{
echo "<br><br><br>\nInside the encode function, TO START the addy is " . $addr . "<br><br><br>\n";
$output = "";
for ($i = 0; $i < strlen($addr); $i++) {
$output .= sprintf("&#x%X;", ord($addr{$i}));
}
echo "<br><br><br>\nInside the encode function, TO FINISH the addy is " . $output . "<br><br><br>\n";
return $output;
}
//////then the corresponding decode function is below
function decode_addr($addr)
{
return preg_replace('/&#x([A-F0-9]{2});/e', ' chr(0x$1); ', $addr);
}