Search code examples
phpemailappearance

How to edit mail appearance in PHP?


I wonder how that can change the appearance of e-mail that comes to me via PHP?

Here's the email:

I'd like to look something like this for example

This is a PHP code:

<?php
$Ime = $_POST["Ime"];
$Prezime = $_POST["Prezime"];
$NaslovOglasa = $_POST["NaslovOglasa"];
$Email = $_POST["Email"];
$SadrzajOglasa = $_POST["SadrzajOglasa"];
$Kontakt = $_POST["Kontakt"];

if (isset($_POST['Istaknut_Oglas'])) {
$IstaknutOglas = "Da";
} else {
$IstaknutOglas = "Ne";
}

if (isset($_POST['Standardni_Paket'])) {
$StandardniPaket = "Da";
} else {
$StandardniPaket = "Ne";
}

$Za = "[email protected]";
$Od  = "Od: " . $Email . "\r\n";
$Info .= "|NOVI OGLAS|" . "\r\n";
$Info .= "Ime: " . $Ime . "\r\n";
$Info .= "Prezime: " . $Prezime . "\r\n";
$Info .= "Naslov oglasa: " . $NaslovOglasa . "\r\n";
$Info .= "Sadrzaj oglasa: " . $SadrzajOglasa . "\r\n";
$Info .= "Kontakt informacije: " . $Kontakt . "\r\n";
$Info .= "Istaknut oglas: " . $IstaknutOglas . "\r\n";
$Info .= "Standardni paket: " . $StandardniPaket . "\r\n";
$Info .= "" . "\r\n";

if(isset($_FILES['file_array'])){
$name_array = $_FILES['file_array']['name'];
$tmp_name_array = $_FILES['file_array']['tmp_name'];
$type_array = $_FILES['file_array']['type'];
$size_array = $_FILES['file_array']['size'];
$error_array = $_FILES['file_array']['error'];  
for($i = 1; $i < count($tmp_name_array); $i++){
    if(move_uploaded_file($tmp_name_array[$i], "adsuploads/".$name_array[$i])){
        $Info .= "Fotografija ".$i.": ".$name_array[$i]. "\r\n"; 
    }
}
mail($Za, $Od, $Info);
header("Location: http://bratunacinfo.000webhostapp.com/pages/postavi_oglas-3");
}
?> 

I wonder if this can be done via php me or I need some framework


Solution

  • You can send your email as an HTML email. For example:

    <?php
        $to = "[email protected]";
        $subject = "Some email title";
        $content = "
        <html>
            <head>
                <title>HTML email</title>
            </head>
            <body>
                <p>This email contains HTML Tags!</p>
                <table>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                    </tr>
                    <tr>
                        <td>John</td>
                        <td>Doe</td>
                    </tr>
                </table>
            </body>
        </html>
        ";
    
        $headers = "MIME-Version: 1.0\r\nContent-type:text/html;charset=UTF-8\r\n";
        mail($to, $subject, $content, $headers);
    ?>
    

    For more information you can visit this.