Text direction and alignment in email sent via email() using PHP
Asked Answered
S

4

5

I am sending an automatic email via php. The email contains Hebrew which direction is right to left. Here is my code for making up the body part of the message:

            $emailMessage ='
            <html lang="HE">
                <head>
                <title>
                    job-skills | הצורפות
                </title>
                </head>
                <body style="text-align:right; direction:rtl;">
                    <table>
                        <tr>
                            <td><h3>תודה על הצטרפותך</h4></td>
                        </tr>
                        <tr>
                            <td>על מנת להצטרף סופית לאתר עליך ללחץ על הלינק הבא:</td>
                        </tr>
                        <tr>
                            <td><a href="http://localhost/W-DB/php/registration_and_login/confirm_registration.php?email=' .$registrationEmail .'&tempPass=' . $tempPass . '>לחץ כאן</a></td>
                        <tr>
                        </tr>
                        <tr>
                            <td>בברכה,</td>
                        </tr>
                        <tr>
                            <td><h2>JOb-Skills</h2></td>
                        </tr
                    </table>
                </body>
            </html>

still the text aligned to left and direction left to right.

Shoemaker answered 9/10, 2012 at 12:26 Comment(2)
This is probably an issue with the email clients' capabilities (RichText/HTML rendering strategy). Is HTML delivered correctly to your client and did you set the correct Content-Type and other headers? Please provide some additional information.Cand
This is the message that I'm sending nothing more. What more should I add to it?Shoemaker
I
11

Here is my code:

<?php 
$to ="mail id";
$from = "mail id";
$sub = "Hebrew";
$message = '<html lang="HE">
                <head>
                <title>
                    job-skills | הצורפות
                </title>
                </head>
                <body style="text-align:right; direction:rtl;">
                    <table>
                        <tr>
                            <td><h3>תודה על הצטרפותך</h4></td>
                        </tr>
                        <tr>
                            <td>על מנת להצטרף סופית לאתר עליך ללחץ על הלינק הבא:</td>
                        </tr>
                        <tr>
                            <td>
    <a href="#">לחץ כאן</a></td>
                        <tr>
                        </tr>
                        <tr>
                            <td>בברכה,</td>
                        </tr>
                        <tr>
                            <td><h2>JOb-Skills</h2></td>
                        </tr
                    </table>
                </body>
            </html>';
$headers = "From:" . $from;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
if(mail($to,$sub,$message,$headers)) echo "success";



?>
Integral answered 10/10, 2012 at 12:22 Comment(2)
It is funny, it works fine in Gmail but in Outlook it is still in wrong direction. ThanksShoemaker
@Shoemaker I have the same problem. Have you found a way around it?Stasny
B
2

Please refer to style @Varun placed in the body: <body style="text-align:right; direction:rtl;"> Only after I added this style to the body it worked also on gmail, until then It was working only on Outlook.

Bendicty answered 15/5, 2014 at 13:22 Comment(0)
I
1

Try adding dir="rtl" to your HTML tag.

Integral answered 9/10, 2012 at 12:38 Comment(0)
I
1

enter image description here

It is working fine with the code I mentioned. Please have a look to the attached image.

Integral answered 10/10, 2012 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.