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 »
Q&A

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

71%
+3 −0
Q&A PHP variables aren't expanded when inside HTML which is by itself inside PHP

I transfer emails from my Right To Left (RTL) contact form → to my local email box (powered by Roundcube). Emails reach my email box (inbox) just fine but I have a problem were PHP variables aren'...

1 answer  ·  posted 3y ago by deleted user  ·  last activity 3y ago by luap42‭

Question php email
#1: Initial revision by (deleted user) · 2021-03-28T09:37:41Z (about 3 years ago)
PHP variables aren't expanded when inside HTML which is by itself inside PHP
I transfer emails from my Right To Left (RTL) contact form → to my local email box (powered by [Roundcube](https://roundcube.net/)).

Emails reach my email box (inbox) just fine but I have a problem were PHP variables aren't expanded inside the string of the `$message` variable so I get the literal variables instead their values sent via the form → although I have tried various ways to escape them as _PHP in HTML which is by itself in PHP_ (I might have made a mistake somewhere along the way).

## PHP code

```php
<?php
	$name = $_POST['name'];
	$email = $_POST['email'];
	$phone = $_POST['phone'];
	$topic = $_POST['topic'];
	$date = $_POST['date'];
	$time = $_POST['time'];
	$notes = $_POST['notes'];

	$to = 'example@example.com';

	$subject = 'הודעת אימייל חדשה מאת: ' . $name;
	
	$message = '
	<html>
		<body dir="rtl" style="text-align: right;">
			<b>שם: </b> $name <br>
			<b>אימייל: </b> $email <br>
			<b>טלפון: </b> $phone <br>
			<b>פנייה בנושא: </b> $topic <br>
			<b>יום רצוי לפגישה מרחוק (אם יש): </b> $date <br>
			<b>שעה רצויה לפגישה מרחוק (אם יש): </b> $time <br>
			<b>הערות (אם יש): </b> $notes <br>
		</body>
	</html>
	';

	$headers[] = 'MIME-Version: 1.0';
	$headers[] = 'Content-type: text/html; charset=utf-8';

	mail($to, $subject, $message, implode("\r\n", $headers));
?>
```

## Current Output

<div dir="rtl" style="padding: 5px; background: #ddd">
<b>שם:</b> $name<br>
<b>אימייל:</b> $email<br>
<b>טלפון:</b> $phone<br>
<b>פנייה בנושא:</b> $topic<br>
<b>יום רצוי לפגישה מרחוק (אם יש):</b> $date<br>
<b>שעה רצויה לפגישה מרחוק (אם יש):</b> $time<br>
<b>הערות (אם יש):</b> $notes<br>
</div>

## Desired output:

<div dir="rtl" style="padding: 5px; background: #ddd">
<b>שם:</b> שם_רלוונטי<br>
<b>אימייל:</b> אימייל_רלוונטי<br>
<b>טלפון:</b> טלפון_רלוונטי<br>
<b>פנייה בנושא:</b> נושא_רלוונטי<br>
<b>יום רצוי לפגישה מרחוק (אם יש):</b> SOME_DATE<br>
<b>שעה רצויה לפגישה מרחוק (אם יש):</b> SOME_HOUR_AND_MINUTE<br>
<b>הערות (אם יש):</b> הערה_רלוונטית<br>
</div>


## My question

As a non PHP programmer I ask how would you suggest to solve that problem?