Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Emil Wallgren
Emil Wallgren
11,737 Points

The form won't redirect to thank-you page after php-process

Please take a look at this page: http://www.hipchap.se/stadakuteninorr.se/kontakt/

Do you get a thank-you page ("Tack in swedish") after sending the form. For me it stops at the url process-tack.php.

the code for the process-tack.php is

<html>
<head>
    <meta charset ="utf-8">
</head>
<body>
<?php 

    $name = $_POST['name'];

    $email = $_POST['email'];

    $ort = $_POST['ort'];

    $telefon = $_POST['telefon'];

    $klickad = "None";
        if(isset($_POST['klickad'])){
        $klickad = implode(", ", $_POST['klickad']);}

    $message = $_POST['message'];

    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/plain; charset=utf-8\r\n";
    $headers .= "Content-Transfer-Encoding: 8bit\r\n";
    $headers .= "From: $email \r\n";


    $to = "emil.wallgren@hotmail.se";
    $subject = "StädAkuten | Meddelande";
    $msg =  "Namn: $name \n" . 
            "-------------------------------\n" .
            "Kundens e-mail: $email \n" .
            "-------------------------------\n" .
            "Kundens telefon: $telefon \n" .
            "-------------------------------\n" .
            "Kundens ort: $ort \n" . 
            "-------------------------------\n" .
            "Vill ha hjälp med: $klickad \n" .
            "-------------------------------\n" .
            "Meddelande:\n $message";

    mail($to, $subject, $msg, $headers);

    header("Location: tack");
?>
</body>
</html> 

Don't worry about the Swedish...But do you see something wrong in this code?

Regards!

/Emil

I haven't looked into your error at all, but I noticed you have html outputted before a header redirect. I would move your entire PHP code block above all of the html. Are you getting an error from this?

1 Answer

Emil Wallgren
Emil Wallgren
11,737 Points

Removed the html completely. Now it works! I'll se if it outputs in utf-8 though, when the meta charset is gone. But thanks anyway :-)

You just needed to move below the <?php ?> code block above ALL of your html, you didn't have to remove anything.

Emil Wallgren
Emil Wallgren
11,737 Points

I know :-) But it's an easy fix :-) Thanks Jason :-)