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      = "info@domain.com";

      $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
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";

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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      = "info@domain.com";
      $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

Link to comment
Share on other sites

The page which has the enquiry form on has:

<?php header('Content-type: text/html; charset=utf-8'); ?>

If i alter this to iso, it fixes the email, however, it stuffs up the rest of the page. So, is there a way around this?

 

Many thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.