Domanda

Having some troubles with a contact form.

When pressing submit I get redirected to http://minerva.hivolda.no/~oleav/eksamensandkasse/kontakt/ (same page), and recieve a message that my site was not found etc.

function haugsdalen_kontaktplugin () {
    function haugsdalen_kontakt_header () {
    echo ('<link rel="stylesheet" type="text/css" href="'.plugin_dir_url( __FILE__ ).'haugsdalen-kontakt.css">');   
    }

    $from = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $to = 'MYMAIL'; 
    $subject = 'Ny melding fra Haugsdalen Skisenter';
            
    $body = "Ny melding fra Haugsdalen Skisenter:\n Fra: $name\n E-post: $email\n Melding:\n $message";
    
    echo ('<div id="kontakthead">');            
    if ($_POST['submit']) {              
        if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Din melding har blitt sendt!</p>';
    } else { 
        echo '<p>Noe gikk galt. Vennligst prøv igjen.</p>'; 
    } 
    } 
    echo ('<form method="post" action="http://minerva.hivolda.no/~oleav/eksamensandkasse/kontakt/">
    <h2>Kontakt</h2>   
    <label>Navn</label>
    <input name="name" placeholder="Ditt navn">
            
    <label>E-post</label>
    <input name="email" type="email" placeholder="Din e-post">
            
    <label>Melding</label>
    <textarea name="message" placeholder="Din melding..."></textarea>
            
    <input id="submit" name="submit" type="submit" value="Send inn"></form><br/>
    <h3><strong>Kontaktinformasjon:</strong></h3>
    Tlf: 73 85 46 05<br/>
    E-post: web@haugsdalen.com<br/>
    </div>');
}

Any suggestion? Page can be found here: http://minerva.hivolda.no/~oleav/eksamensandkasse/kontakt/

EDIT: I recieve my messages now, but the messages just contains:

Ny melding fra Haugsdalen Skisenter: Fra: E-post: Melding:

However I just recived one mail with some text:

E-post: 2@2.co Melding: 3

È stato utile?

Soluzione

There is error somewhere else in your code related to the $_POST['name'] variable. When I delete this DOM node (input with name="name") and submit data everything working as expected, I've got mail function executed and your script echoed Din melding har blitt sendt!.

It seems that this script or some of your included scripts generate 404 error exception when you send any unexpected $_POST['name'] data.

I suggest you to try renaming this name="name" to name="from", for example.

Altri suggerimenti

Could you post the whole code of the webpage? We need to see the function calls.

Also,

Add required to each input field to reduce the number of spams or use some captcha mecanism.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top