簡體   English   中英

PHP /HTML BOOTSTRAP 4 聯系我們 Web 表格

[英]PHP /HTML BOOTSTRAP 4 Contact Us Web form

嗨,我是學習者,我想在我的網站上使用動態聯系我們表單,但在嘗試使用 HTML/PHP/PEAR 使其動態化時遇到問題我在這里很困惑如何為與 Mochahost 一起使用的實際表單編寫 php 腳本

測試在服務器上運行良好,但我的問題是我不知道如何編寫 php 腳本以使其動態(實際消息來自 web 頁面)


<?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>");
}
?>

您要做的是創建一個帶有<form>元素的 HTML“聯系我們”頁面,為其提供 PHP 頁面的路徑和方法,您將在其中處理他們輸入的所有信息,這是一個小例子你開始了

聯系我們。html:

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

聯系我們。php:

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

依此類推,當然在 HTML 頁面上,您要設置表單樣式,並添加您向訪問者詢問的任何其他信息,在 PHP 頁面上,您要添加“謝謝”消息或一些告訴您的訪問者他們的請求是成功的,因為它會將他們從您的contactUs.html頁面重定向到您的contactUs.php頁面,盡管有一些方法可以在保持在同一頁面上的同時完成相同的任務。

在重新映射和優化 php 腳本后,它的工作和粘貼它可能對其他腳本也有幫助。 希望讓它更先進。

<?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>");
}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM