Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: E-mail with correct charset  (Read 2887 times)

Manuel Pancorbo

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 72
E-mail with correct charset
« on: November 20, 2006, 11:25:55 PM »

The actual contact form does not sed e-mail with information about charset coding. When charset different from  the default in many mail readers is defined in the site, the recipient receives garbage.

I propose the following code to correct this matter:

Quote
// CONTACT FORM
function contact() {
   if ($_POST['contactform'] == '') {
      echo '

'.l('contact').'

';
      html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', db('website'), '');
      html_input('text', 'name', 'name', '', '* '.l('name'), 'text', '', '', '', '', '', '', '', '', '');
      html_input('text', 'email', 'email', '', '* '.l('email'), 'text', '', '', '', '', '', '', '', '', '');
      html_input('text', 'weblink', 'weblink', '', l('url'), 'text', '', '', '', '', '', '', '', '', '');
      html_input('textarea', 'message', 'message', '', '* '.l('message'), '', '', '', '', '', '5', '5', '', '', '');
      echo '

';
      html_input('hidden', 'ip', 'ip', $_SERVER['REMOTE_ADDR'], '', '', '', '', '', '', '', '', '', '', '');
      html_input('hidden', 'time', 'time', time(), '', '', '', '', '', '', '', '', '', '', '');
      html_input('submit', 'contactform', 'contactform', l('submit'), '', '', '', '', '', '', '', '', '', '', '');
      echo '

';
   }
   if (isset($_POST['contactform']) && $_POST['ip'] == $_SERVER['REMOTE_ADDR'] && (time() - $_POST['time']) > 5) {
      $to = s('website_email');
      $subject = s('contact_subject');
      $name = cleanXSS($_POST['name']);
      $mail = cleanXSS($_POST['email']);
      $url = cleanXSS($_POST['weblink']);
      $message = cleanXSS($_POST['message']);
      $body = $name.", ".$url."\n\n".$message."\n";
      $from_header = 'From: '.strtolower($mail);
       $from_header .= "\nContent-type: text/plain; charset=".s('charset')."\n";
      if (strlen($name) > 3 && strlen($message) > 9 && strlen($mail) > 6) {
         mail($to, $subject, $body, $from_header);
         notification('','','');
         echo '

'.l('backhome').'

';
         echo '';
      }
      else {
         notification(l('contact_not_sent'),l('message_error'),'contact/');
         echo '';
      }
   }
}
Logged

tobto

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 71
    • seo service
E-mail with correct charset
« Reply #1 on: June 07, 2007, 07:21:36 PM »

Good job!
Tried - working!
Logged