【问题标题】:PHP /HTML BOOTSTRAP 4 Contact Us Web formPHP /HTML BOOTSTRAP 4 联系我们 Web 表单
【发布时间】:2021-04-26 15:32:32
【问题描述】:

您好,我是学习者,我想在我的网站上使用动态联系我们表单,但在尝试使用 HTML/PHP/PEAR 使其动态化时遇到问题 我在这里很困惑如何为与 Mochahost 一起使用的实际表单编写 php 脚本

测试在服务器上运行良好,但我的问题是我不知道如何编写 php 脚本以使其动态化(实际消息来自网页)


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

【问题讨论】:

    标签: javascript php html bootstrap-4


    【解决方案1】:

    您要做的是创建一个带有&lt;form&gt; 元素的HTML“联系我们”页面,为它提供一个路径和一个方法到您的PHP 页面,您将在其中处理他们输入的所有信息,这里是一个很小的帮助您入门的示例

    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"];
    ?>
    

    等等,当然,在您的 HTML 页面上,您想要为表单设置样式,并添加您要求访问者提供的任何其他信息,在您的 PHP 页面上,您想要添加“谢谢”消息或一些告诉您的访问者他们的请求成功的消息,因为它会将他们从您的contactUs.html页面重定向到您的contactUs.php页面,尽管有一些方法可以在保持在同一页面上的同时完成相同的任务。

    【讨论】:

    • 当我试图调用它时,它不能以实际形式工作并显示错误“验证不起作用”
    • 这意味着您的验证码有错误?你的验证是什么?
    • 我正在使用 js 来验证数据.. 当我尝试使用 pear 测试通过服务器使用预先创建的 php 脚本喊出邮件时,测试正在运行,但是当实际尝试调用表单 $from 的字段时电子邮件、主题和消息 .. 显示验证错误。
    • $name = $_POST["Full_Name"]; $email = $_POST["email"]; $主题 = $_POST[“主题”]; $message = $_POST["message"];这部分我面临的问题该怎么办? $email_from = "?"; $email_subject = "新邮件:" ; $email_body = "?"; $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' => $密码)); $mail = $smtp->send($to, $headers, $email_body);
    • 我在回答中给出的示例只是一个示例,您需要为电子邮件主题或来自或正文或目的地添加其余的输入字段或文本区域
    【解决方案2】:

    在重新映射和优化 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>");
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      相关资源
      最近更新 更多