Skip to content
Advertisement

PHP HTML Contact us form issue

I am using html ( bootstrap4) contact us page and trying to make it dynamic . server test ok with the php test script using pear mail.

But issue when trying to make dynamic and calling filed out put in email its not working

Can any one review below php script and tell me where is issue

HOW can I call here this part : $email_subject ? email body ? and email message ?

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

Advertisement

Answer

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

<?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>");
}
?>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement