使用PHP通过email()发送的电子邮件中的文本方向和对齐方式

使用PHP通过email()发送的电子邮件中的文本方向和对齐方式

问题描述:

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.

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' . "
";
$headers .= 'Content-type: text/html; charset=utf-8' . "
";
if(mail($to,$sub,$message,$headers)) echo "success";



?>

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

enter image description here

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

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.