Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

javascript - 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 = "[email protected]";
$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>");
}
?>

question from:https://stackoverflow.com/questions/65840538/php-html-bootstrap-4-contact-us-web-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...