0

Im trying to fix this issue for the past 3 days, but nothing is working..

I have a contact form and I wrote a php code to get the messages to my email.

Here is my contact form? [ I use bootstrap ]

                <form class="col-lg-6" action="kontakt-confirmation.php" method="POST">
                <div class="form-group">
                    <label>Namn <span id="mustdo">*</span></label>
                    <input id="namn" name="namn" class="form-control" type="text" aria-describedby="nameHint"
                        placeholder="Namn" required>
                    <small id="nameHint" class="form-text text-muted">Fyll i formuläret nedan så kontaktar vi
                        dig!!</small>
                </div>
                <div class="form-group">
                    <label>E-postadress <span id="mustdo">*</span></label>
                    <input id="email" name="email" class="form-control" type="email" placeholder="Din e-post" required>
                </div>
                <div class="form-group">
                    <label>Subject <span id="mustdo">*</span></label>
                    <input id="subject" class="form-control" type="text" placeholder="Your subject.." required>
                </div>
                <div class="form-group">
                    <label for="message">Meddelande <span id="mustdo">*</span></label>
                    <textarea id="message" name="message" class="form-control" rows="5" required></textarea>
                </div>
                <button type="submit" name="submit" class="btn btn-lg btn-outline-primary">Skicka</button>
            </form>

Here is my PHP code:

<?php 

if(isset($_POST)) {
    $namn = $_POST['namn'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $to = '??????????';
    $subject = 'Ticket!';
    $message = "Namn: ".$namn."\n"."Email ".$email."\n"."Problem / Question: "."\n\n".$message;
    $headers = "From: ".$email;

    if(mail($to, $subject, $message, $headers)) {
        echo "Thanks for contacting us!";
    } else {
        echo "Problem!";
    }
}

?>

when I press on submit, i get the Problem message. What can i change to fix this? thanks

1 Answers1

0

Hope this resolves your answer to the question :)

if(isset($_POST)) {
    $namn = $_POST['namn'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $to = '??????????';
    $subject = 'Ticket!';
    $message = "Namn: ".$namn."\n"."Email ".$email."\n"."Problem / Question: "."\n\n".$message;
    $headers = "From: ".$email;

    // Always set content-type when sending HTML email
    $headers .= "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";


    if(mail($to, $subject, $message, $headers)) {
        echo "Thanks for contacting us!";
    } else {
        echo "Problem!";
    }
}
BhAvik Gajjar
  • 473
  • 3
  • 19