PHP for simple HTML-PHP-CSS contact form --- aimed solely for RTL websites
+0
−0
As a non PHP programmer I have tried to program some basic PHP mail()
function code to send Right To Left (RTL) contact form messages to my local email client (i.e. an email client which is affiliated with the same web domain of my website hosting machine).
The code does its task; contact form RTL messages indeed reach my local email box and the output is RTLized as expected but I guess I lack some backend validation there and perhaps some other things --- please opine about my PHP code.
contact_form.php
<?php
$topic = $_POST['topic']; # Required;
$name = $_POST['name']; # Required;
$email = $_POST['email']; # Required;
$url = $_POST['url']; # Name attribute is "url" but input type is "text" because "url" obligates http:// or https:// which users normally don't input
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$notes = $_POST['notes'];
$to = '[email protected]';
$subject = 'הודעה חדשה מאת: ' . $name;
include 'message.php';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';
mail($to, $subject, $message, implode("\r\n", $headers));
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
header('Location: $contact_form_success_webpage');
exit;
}
?>
message.php
<?php
$message = <<<LABEL
<html>
<head>
<style>
* {
font-size: 20px;
}
a {
unicode-bidi: plaintext !important;
}
.form_output_col_1 {
font-weight: bold;
}
</style>
</head>
<body dir="rtl" style="text-align: right;">
<div><span class="form_output_col_1">נושא: </span><span class="form_output_col_2">$topic</span></div>
<div><span class="form_output_col_1">שם: </span><span class="form_output_col_2">$name</span></div>
<div><span class="form_output_col_1">אימייל: </span><a dir="ltr" href="mailto:$email" class="form_output_col_2">$email</a></div>
<div><span class="form_output_col_1">אתר: </span><a dir="ltr" href="$url" target="_blank" class="form_output_col_2">$url</a></div>
<div><span class="form_output_col_1">טלפון: </span><a dir="ltr" href="tel:$phone" class="form_output_col_2">$phone</a></div>
<div><span class="form_output_col_1">תאריך: </span><span class="form_output_col_2">$date</span></div>
<div><span class="form_output_col_1">שעה: </span><span class="form_output_col_2">$time</span></div>
<div><span class="form_output_col_1">הערות: </span><span class="form_output_col_2">$notes</span></div>
</body>
</html>
LABEL;
?>
1 comment
I deliberately avoid sharing the rest of the form's code; HTML, CSS, Shell (Bash) because the purpose of this post is to focus only on the PHP. BTW, there is no JavaScript involved, pretty much on purpose. — JohnDoea 6 days ago