-1

How to send mail using php by insert html into mail content ?

I tried to insert html code inner $message, When i test it's show error

like this Parse error: syntax error, unexpected 'margin' (T_STRING)

How can i do ?

<?PHP
include("connect.php");
$email = "test_mail@hotmail.com";    
$to = $email;
$subject = "test subject";
$message = "

<body style="margin: 0; padding: 0;">
    <table border="1" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td>
                <img src="https://i.stack.imgur.com/Jy9QUm.jpg"/>
            </td>
        </tr>
        <tr>
            <td>
                test text
            </td>
        </tr>
    </table>
</body>

";

$headers  = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply@example.com>' . "\r\n";
$headers .= 'Return-Path: return@example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn@example.com');
?>

1 Answers1

1

You have an issue with wrapping your $body string try this

 <?PHP
    include("connect.php");
    $email = "test_mail@hotmail.com";    
    $to = $email;
    $subject = "test subject";
    $message = "

    <body style='margin: 0; padding: 0;'>
        <table border='1' cellpadding='0' cellspacing='0' width='100%'>
            <tr>
                <td>
                    <img src='https://i.stack.imgur.com/Jy9QUm.jpg'/>
                </td>
            </tr>
            <tr>
                <td>
                    test text
                </td>
            </tr>
        </table>
    </body>

    ";

    $headers  = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: EXAMPLE <noreply@example.com>' . "\r\n";
    $headers .= 'Return-Path: return@example.com' . "\r\n";
    mail($to, $subject, $message, $headers, '-freturn@example.com');
    ?>
Yehia Awad
  • 2,898
  • 1
  • 20
  • 31