Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. UTF-8 format with mail()

UTF-8 format with mail()

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
questionphphtmldatabasesysadmin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    grmihel2
    wrote on last edited by
    #1

    Hi php folks... I decided to try to make an PHP script that a webform could call, to send an email, so I doesn't need the ugly mailto:xxx@yyy.domain in the form action. So I have 2 pages. 1 frontend (html) and 1 backend (php). The frontend contain an webform that on submit using the backend php as action, so its like: index.html sendemail.php action="sendemail.php" (in the index.html form). Everything works fine, and I recieving the emails as supposed... I have configured the php.ini to use my own smtp server (which I use at work too, so I know the SMTP server works). the issue now is, that I want to send my emails as utf-8 format, cuz the need of some special characters inside the email?!? I'm using the mail($to, $subject, $body, $header); as function right now... And when I type in some utf-8 formatted characters like ø, its viewed as ?? in the recieved email :( How can I send my email()'s as utf-8? I have try following: - Set header of the email to utf-8:

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
    $headers .= 'From: ' . $_POST['email'] . "\r\n";

    I'm using Eclipse PHP as php editor for development.

        $dato = date("d-m-y");
    $to = "your@domain.dk";
    $subject = "Web $dato";
    $headers = 'MIME-Version: 1.0' . "\\r\\n";
    $headers .= 'Content-Type: text/plain; charset=utf-8' . "\\r\\n";
    $headers .= 'From: ' . $\_POST\['email'\] . "\\r\\n";
    
    if($\_POST\['street'\] != "")
    	$street = $\_POST\['street'\];
    if($\_POST\['no'\] != "")
    	$no = $\_POST\['no'\];
    if($\_POST\['floor'\] != "")
    	$floor = $\_POST\['floor'\];   	
    if($\_POST\['name'\] != "")
    	$name = $\_POST\['name'\];
    
    //Set email body
    $newline = "\\r\\n";
    $body = "Date: $dato" . $newline .
    $street . " " . $no . ", " . $floor . "." . $nnewline .
    $navn;
    			
    //Send email
    mail($to, $subject, $body, $headers);
    

    Whitebox test: Input: $street = "ø"; $no = "53st"; $floor = "2nd"; $name = "æøå"; $dato = "20-09-2010"; Output SHOULD be:

    Date: 20-09-2010
    ø 53st, 2nd.
    æøå

    Actual output:

    Date: 20-09-2010
    ?? 53st, 2nd.
    ??????

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups