简体   繁体   中英

PHP /HTML BOOTSTRAP 4 Contact Us Web form

Hi I am learner and i want to use dynamic contact us form on my site but facing issue when trying to make it dynamic using HTML/PHP/ PEAR I am confused here how to write php script for actual form that work with Mochahost

Test is working perfectly on the server but my issue is i don't know how to write the php script to make it dynamic ( actual message getting from web page )


<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
require_once "Mail/Mail-1.4.1/Mail.php";
$host = "mail.example.com";
$username = "siri@example.com";
$password = "********";
$port = "2525";
$to = "?";
$email_from = " how dynamical i can see the emails here ?";
$email_subject = "how i can get the subject from my email form that user fielded? " ;
$email_body = "want to see the message user types in my inbox ?" ;
$email_address = "?";
$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

What you want to do is create an HTML "Contact Us" page with a <form> element, giving it a path and a method to your PHP page where you will handle all the information they put in, here is a tiny example to get you started

contactUs.html:

<form action="contactUs.php" method="POST">
    <input type="text" name="username" />
    <input type="password" name="userPassword" />
    <input type="email" name="userEmail" />
</form>

contactUs.php:

<?php
    $username = $_POST["userName"]; //We access the name attributes from our HTML form here
    $password = $_POST["userPassword"];
    $email = $_POST["userEmail"];
?>

And so forth, of course on your HTML page you want to style the form, and add any other information that you are asking from your visitor, and on your PHP page you want to add a "Thank you" message or some message that tells your visitor that their request was successful since it will redirect them away from your contactUs.html page and to your contactUs.php page, although there are ways of accomplishing the same task while staying on the same page.

After remapping and optimized the php script its working and here pasting it might be helpful for the other as well. Looking to make it more advanced.

<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
require_once "Mail/Mail-1.4.1/Mail.php";
$name = $_POST["Full_Name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$host = "mail.example.com"; 
$username = "xyz@example.com";
$password = "abc";
$port = "25";
$to = "xyz@example.com";
$reply_to = "xyz@example.com"; 
$headers = array ('From' => $email, 'To' => $to, 'Subject' => $subject, 'Reply-To' => $reply_to);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $message);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM