Jump to content

Php form


yangmanrui

Recommended Posts

I have a website where people can learn languages and I would like to add a simple form there. http://www.languagelearninglinks.info/contact.htm

Somebody gave me this script, but for some reason it doesn't work. (Could you please someone take a look at it, suggest what I am doing wrong and help me make it work?)

 

 

thanks

 

manrui

 

 

<?php

 

if(isset($_POST['email']) && isset($_POST['message']))

{

   

    $name = $_POST['name'];

 

    $email = $_POST['email'];

    $msg = $_POST['message'];

   

    // You'll want to validate the email and make sure that no one is trying to send this feedback to some one else as well.

    if(eregi("to:",$email) || eregi("cc:",$email) || eregi('bcc:',$email))

        echo'Sorry, we couldn\'t send your message, please try again.';

   

    if(!ereg('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$', $email))

        echo'Sorry, you entered an invalid email address!';

 

/*

* You may also want to run a strip_tags on the message so you don't get radnom html/JS in your emails

*/

    $msg = strip_tags($msg);

   

/*

* Please be away that this can still be attacked by spam bots and they may use this to send you junk emails.

*/

 

    $to = "[email protected]";

    $subject = "Feedback";

    $headers = "From: $name <$email>";

 

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

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/91958-php-form/
Share on other sites

Basically, you've tried to use .html as php, take your script and place it in a separate file and name it something like sendmessage.php, then inside your contact.htm file edit this:

<form name="form1" method="post" action="">

 

and change it to this:

 

<form name="form1" method="post" action="sendmessage.php">

 

You can change sendmessage.php for what ever you decide to call the new file.

 

Also, you should really notify your users that their message has been sent, so swap this

 

/*

* Please be away that this can still be attacked by spam bots and they may use this to send you junk emails.

*/

 

    $to = "[email protected]";

    $subject = "Feedback";

    $headers = "From: $name <$email>";

 

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

 

}

 

Swap it for:

 

/*

* Please be away that this can still be attacked by spam bots and they may use this to send you junk emails.

*/

 

    $to = "[email protected]";

    $subject = "Feedback";

    $headers = "From: $name <$email>";

 

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

 

    header('location:thanks.html');

 

}

 

And create a page called thanks.html, it will come up after some one has contacted you.

 

Link to comment
https://forums.phpfreaks.com/topic/91958-php-form/#findComment-470991
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.