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 = "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>"); } ?>
Advertisement
Answer
After remapping and optimized the php script its working and here pasting it might be helpful for the other as well. Looking to make it more advanced.
<?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>"); } ?>