Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP contact page doesn’t work

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #44049

    Hello,

    I have made a php contact page and everthing seems to work, the only problem he sends nothing.

    when you enter the page it says that all is well and “message sent”, but when I look at my mail I do not see anything.

    Here is the pen http://codepen.io/KlappenVanJePa/pen/amIuJ

    Sorry for my bad English, I hope you understand my question.

    #131482
    __
    Participant

    this:

    mail($to, $subject, “From: $email”);

    …is the first part of your problem. You’re putting your email headers where the email body should be.

    Maybe you meant to do this?

    $body = << email: $email
    naam: $naam
    Onderwerp: $onderwerp
    vraag: $vragen
    EMAIL;

    # note, mail() comes *after* $body

    # in your codepen,
    # you try to write the email message
    # *after* you send the email

    mail( $to,$subject,$body,”From: $email” );

    However, your email headers are also malformed – you need to include line breaks after:

    “From: $emailrn”

    Also, the `From` header should contain an address on the domain that actually *sent* the email (meaning *your* domain), not the email your visitor provided. It is very common for emails to get discarded as spam for this reason, long before getting to your inbox. *(You might even get your web host’s mail server blacklisted, and they will be upset!)*

    Also, a good habit is to make sure `mail()` was successful before telling the user their message was, indeed, sent.

    Try it like so:

    $to = ‘{your email address}’;

    $subject = ‘contact’;

    $body = << email: $email
    naam: $naam
    Onderwerp: $onderwerp
    vraag: $vragen
    EMAIL;

    $headers = “From: no-reply@{your domain}rn”;
    $headers .= “Reply-to: $naam <$email>rn”;

    if( mail( $to,$subject,$body,$headers ) ){
    # success!
    echo “Bericht verzonden!”;
    }
    else{
    # failed!
    echo “Bericht niet verzonden!”;
    }

    #131554

    Thanks, but when I now upload the file and I fill in the form there comes a new error:
    “Parse error: syntax error, unexpected $end in /srv/disk6/1361896/www/portfolio-tw.co.nf/gelukt.php on line 26”
    I’ve looked it up and it says that I do not have closed something, but I can’t find the problem.

    http://portfolio-tw.co.nf/invul.php

    #131560
    __
    Participant

    Can you post your current code so I can check it out?

    #131563
    #131612
    __
    Participant

    two things:

    If you copied/pasted that directly from my post, you’re going to need to do a little fixing. Here on css-tricks, I have to indent the code to make it display in a code block. HOWEVER, a “real” heredoc must have NO characters on the closing line except the closing token.

    So, `EMAIL;` (NO spaces or anything else!) will work;
    but `…EMAIL;` (pretend those . are spaces) will BREAK EVERYTHING.

    second,

    You’re not showing the part of the code where you got the values from the form (`$name = $_POST`, etc.). I don’t know if you just left them out of your example, but you still need to do that.

    #131707

    Thanks, I have noticed that that is not the only problem was, the other problem was that .co.nf didn’t support php but they say it on there front page.

    Thank you very much

    #131708
    __
    Participant

    The code is being parsed (as evidenced by your error messages), so they *do* support PHP.

    Do they not support the `mail()` function?

    #133410
    ArmsVsLegs
    Participant

    Klappen, I’ve had issues to do with the messages sent by the php mail function just being blocked by the recipient for having malformed headers. Have you set all the parameters?

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Back End’ is closed to new topics and replies.