Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Code Reviews

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Code Reviews PHP for simple HTML-PHP-CSS contact form --- aimed solely for RTL websites

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 affilia...

1 answer  ·  posted 3y ago by deleted user  ·  last activity 4mo ago by GeraldS‭

#1: Initial revision by (deleted user) · 2021-04-05T05:22:03Z (over 3 years ago)
PHP for simple HTML-PHP-CSS contact form --- aimed solely for RTL websites
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
<?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 = 'example@example.com';
	$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
<?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;
?>
```