we will learn in this lesson the way of sending an email through getting the textbox value and send it automatically to a specific email once the user clicks the submit button, as you know that this thing is mostly required by the websites' owners' to create a contact us form for the purpose of feedbacks or complaints that are provided by the website visitors or also can be used for any other purpose such as tracking your website.
in this lesson we will perform a (simple contact us form) and then will send the content of the form to a specific email.
let's create a php page with a name of "contact.php", and paste the code below into "contact.php"
<?php
if(isset($_POST['submit'])){
$msg= 'Name: ' .$_POST['name']."\n".'E-mail: '.$_POST['email']."\n".'message: '.$_POST['message'];
mail('youremail@gmail.com','Sample Contact Form',$msg);
echo"your email has been sent to us, thank you";
}
?>
<html>
<body>
<form action="contact.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Message: <input type="text" name="message"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
Notice: in order to execute the process of sending an email, you will need to upload this web page to a web host, the function of sending email doesn't work with localhost server. you can use a free web hosting such as 000webhost.com to test your work.
if you want to send an email from localhost in PHP, then you will need to go through send an email from localhost in php.
if you want to send an email from localhost in PHP, then you will need to go through send an email from localhost in php.
No comments:
Post a Comment