1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem with mail() function and hebrew

Discussion in 'PHP' started by Lora Kok, May 13, 2015.

  1. #1
    Hello all! :)
    I bought this HTML script and it comes with a contact form.
    I get the msg in gibberish :(


    <?php
    
    $to = 'dontlikelimits@outlook.com'; // Replace with your email address
    
    // No need to edit below this line
    if($to) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $subject = $_POST['subject'];
        $message = $_POST['message'];
       
        $html = "";
        $html .= "Name: " . htmlentities($name, ENT_QUOTES, "UTF-8") . "<br>\n";
        $html .= "Email: " . htmlentities($email, ENT_QUOTES, "UTF-8") . "<br>\n";
        $html .= "Message: " . htmlentities($message, ENT_QUOTES, "UTF-8") . "<br>\n";
       
        $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n";
        $headers .= "From: " . $name . "<". $email .">\r\n";
        $headers .= "Reply-To: " .  $email . "\r\n";
       
        $html = utf8_decode($html);
       
        mail($to, "Alexandria Demo - " . $subject, $html, $headers);
       
        if ($html)
            echo 'ok';
        else
            echo 'error';
       
    } else {
        echo "error";   
    }
    ?>
    Code (markup):
     
    Lora Kok, May 13, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Well, the form sends you the email with utf-8 encoding (well, decoded, but still) - is the form itself / your page using utf-8? Or some other character set? If the input isn't utf-8, the script above will probably fail.
     
    PoPSiCLe, May 13, 2015 IP