Jump to content

remove foreign chars from enquiry form


jarvis

Recommended Posts

Hi All,

 

I've got a simple enquiry form, it then uses the following code to send an email:

    // error checking
    $errorsAndAlerts = "";
    if (!@$_REQUEST['name'])                		{ $errorsAndAlerts = "Please fill out all fields\n"; }
    if (!@$_REQUEST['email'])                   { $errorsAndAlerts = "Please fill out all fields\n"; }
    else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "Please fill out all fields\n"; }
    if (!@$_REQUEST['enquiry'])                 { $errorsAndAlerts = "Please fill out all fields\n"; }

    // send email user
    if (!$errorsAndAlerts) {
      $from    = $_REQUEST['email'];
      $to      = "[email protected]";

      $subject = "Quick Contact";
      $message = <<<__TEXT__

Full name: {$_REQUEST['name']}
Email:     {$_REQUEST['email']}
Enquiry:   {$_REQUEST['enquiry']}

 

Problem is it seems to add the following characters into the email:

at £40,000per month

 

What can I do to stop that?

 

TIA

 

jarvis

Link to comment
https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/
Share on other sites

It's because the pound sterling sign (£) is a Unicode 2 byte character, you will need to change the charset you are using for the e-mail. If it is a HTML e-mail then something like...

 

$headers .= "Content-Type: text/html; charset=utf8\r\n";

 

 

Hi,

 

It's a plain text email, how easy is it to conver to html?

Full name: {$_REQUEST['name']}
Email:     {$_REQUEST['email']}
Enquiry:   {$_REQUEST['enquiry']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;
      // Note: The above line must be flush left or you'll get an error
      // This is a PHP heredoc.  See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

      // send message
      $mailResult = @mail($to, $subject, $message, "From: $from");
      if (!$mailResult) { die("Mail Error: $php_errormsg"); }

      //
      $errorsAndAlerts = "Thanks!  We've sent your email.";
      $_REQUEST = array(); // clear form values
    }

  }

Many thanks

Ok, I've altered my code and this should be correct, however, the encoding still isn't working. Here's my code:

    if (!$errorsAndAlerts) {
      $email    = $_REQUEST['email'];
      $to      = "[email protected]";
      $subject = "Quick Contact";


$body =  "Full name: ". $_REQUEST['name'] ."\n\n";
$body .= "Email: ".$_REQUEST['email'] ."\n\n";
$body .= "Enquiry: ".  $_REQUEST['enquiry'] ."\n\n";
$body .= "The user who sent this message had the IP address ".$_SERVER['REMOTE_ADDR']."\n\n";

$message = $body;

$headers  = "MIME-Version: 1.0\r\n";		#html hdr
$headers .= "Content-Type: text/html; charset=utf8\r\n";
$headers .= "From: $email \r\n";		#from

      // send message
      $mailResult = @mail($to, $subject, $message, $headers);
      if (!$mailResult) { die("Mail Error: $php_errormsg"); }

I cannot see where I'm going wrong!

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.