简体   繁体   English

PHP HTML 联系我们 表单问题

[英]PHP HTML Contact us form issue

I am using html ( bootstrap4) contact us page and trying to make it dynamic.我正在使用 html(bootstrap4)联系我们页面并尝试使其动态化。 server test ok with the php test script using pear mail.使用梨邮件的 php 测试脚本服务器测试正常。

But issue when trying to make dynamic and calling filed out put in email its not working但是,当尝试在 email 中进行动态和调用归档时出现问题,它不起作用

Can any one review below php script and tell me where is issue任何人都可以在 php 脚本下方查看并告诉我问题出在哪里

HOW can I call here this part: $email_subject?我如何在这里调用这部分:$email_subject? email body? email 机身? and email message?和 email 消息?

<form id="contact-form" method="post" action="test.php">
  <div class="row">
    <!-- Name -->
    <div class="col-md-6 mb-2">
      <input type="text" name="Full_Name" class="form-control" placeholder="Firstname *" required="required" data-error="Firstname is required.">
    </div>
    <!-- Email -->
    <div class="col-md-6 mb-2">
      <input type="email" name="email" class="form-control" placeholder="email *" required="required" data-error="Valid email is required.">
    </div>
    <!-- subject -->
    <div class="col-md-12 mb-2">

      <input type="text" name="subject" class="form-control" placeholder="subject *" required="required" data-error="Valid subject is required.">
    </div>
    <!-- Message -->
    <div class="col-md-12 mb-2">
      <textarea name="message" class="form-control" placeholder="Message  *" rows="4" required="required" data-error="Please,leave us a message."></textarea>
    </div>
    <!-- Submit Button -->
    <div class="col-12 text-right">
      <input type="submit" class=" form-control btn btn-success btn-send" value="Send message">
    </div>
  </div>
</form>
<!-- Email -->
<div class="col-md-6 mb-2"> <input type="email" name="email" class="form-control" placeholder="email *" required="required" data-error="Valid email is required."> </div>

<?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 = "*******"; <!--i will use my hosting server url-->
$username = "*******"; <!--i will use my email-->
$password = "*****";  <!--i will use here my email pss-->
$port = "2525";
$to = "******";  <!--i will use the email here-->
$email_from = "*****";  <!--how to call email from here by input that i defined above in php file->
$email_subject = "******" ; <!--how to call sujectl from here by input that i defined above in php file->
$email_body = "*****";    <!--how to call message from here by input that i defined above in php file->
$email_address = "*****";   

$headers = array ('From' => $email, 'To' => $to, 'Subject' => $subject, 'Message' => $message, 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>");
}
?>

I've done a slight revamp of the code which might help, also if you're using gmail to send the email please see the last bit of this article: https://help.dreamhost.com/hc/en-us/articles/216140597-How-do-I-send-PHP-mail-via-SMTP-如果您使用 gmail 发送 email 请参阅本文的最后一点:Z5E056C500A1C4B6A7110B50D807.com/BADEh文章/216140597-我如何发送-PHP-mail-via-SMTP-

<?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 = "*******"; <!--i will use my hosting server url-->
$username = "*******"; <!--i will use my email-->
$password = "*****";  <!--i will use here my email pss-->
$port = "2525";

$to = "******";  <!--i will use the email here-->
$reply_to = "*****";   

// Please note the change to the headers
$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>");
}
?>

After carefully reading the code and optimized slightly its working pefrectly and here i am pasting it.. might it be helpful for some one facing the same issue with html/php/pear在仔细阅读代码并对其工作进行轻微优化后,我将其粘贴在这里..可能对面临与 html/php/pear 相同问题的人有所帮助

<?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