-3

I am trying to send a simple HTML e-mail from PHP. so i create a html form and a php script to send it,the email is sending without problem but when i check this email in gmail i get this the body is not a table all what i have is html tag with information

my php script :

<?php
    $name = $_POST['txtfullname'];
    $email = $_POST['txtemail'];
    $comments = $_POST['Comments'];
    $phone = $_POST['optmobileno'];
    $phone .= $_POST['txtmobileno'];
    $date = $_POST['birthdate'];
    $country = $_POST['optcountry'];
    $level= $_POST['optprogrammelevel'];
    $programme= $_POST['txtprogrammepreference'];
    $from = "From: subscription@sendmail.com"; 
    $to = "example@sendmail.com"; 
    $subject = 'New Students';

    $message = '<html><body>';
            $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
            $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($name) . "</td></tr>";
            $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($email) . "</td></tr>";
            $message .= "<tr><td><strong>Phone:</strong> </td><td>" . strip_tags($phone) . "</td></tr>";
            $message .= "<tr><td><strong>Birthdate:</strong> </td><td>" . strip_tags($date) . "</td></tr>";
            $message .= "<tr><td><strong>Contry of residence:</strong> </td><td>" . strip_tags($country) . "</td></tr>";
            $message .= "<tr><td><strong>Programme Level:</strong> </td><td>" . strip_tags($level) . "</td></tr>";
            $message .= "<tr><td><strong>Area of Study:</strong> </td><td>" . strip_tags($programme) . "</td></tr>";
            $message .= "<tr><td><strong>Comments:</strong> </td><td>" . htmlentities($comments) . "</td></tr>";
            $message .= "</table>";
            $message .= "</body></html>";
    $headers = 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();        


      @mail ($to, $subject, $message , $headers)


?>
JV_MI
  • 31
  • 1
  • 3
  • 7

2 Answers2

0

You need to add content-type as html in your email header as like this :

$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

 $headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
Jenis Patel
  • 1,617
  • 1
  • 13
  • 20
0

you need to add header in code

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

use this here is refrence

Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68