1

I am very new to PHP, so be gentle.

It seems I cant run HTML in PHP.

For example when I try to

echo "<script> success(); </script>";

Result will be:

<script> success(); </script>

Another example:

$msg2 = "<b>Dear</b> ".$name ."\n\n" ."Thank you for your registration, we will be contacting you within 48h."."\n\n" ."Yours ....";

Result will be:

<b>Dear</b> (name of the client)

Thank you for your registration, we will be contacting you within 48h.

Yours ....

I checked the meta its:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I will give You guys the code ( some of it is in Estonian )

<?php
    if (isset($_REQUEST['email'], $_REQUEST['nimi'], $_REQUEST['koolitus'], $_REQUEST['telf'], $_REQUEST['kuupaev'], $_REQUEST['tingimused']))  {

    $admin_email = "ville.madison@gmail.com";
    $email = $_REQUEST['email'];
    $koolitus = $_REQUEST['koolitus'];
    $nimi = $_REQUEST['nimi'];
    $kuupaev = $_REQUEST['kuupaev'];
    $telf = $_REQUEST['telf'];
    $marked = $_REQUEST['marked'];
    $kodulehemail = "koolitused@registreerumine.ee";
    $koolitaja = $_REQUEST['koolitaja'];
    $beauty = "info@beautyfactory.ee";
    $msg = "Koolitusele registreerumine: " . $koolitus . "\n" . "Soovitud koolitaja: " . $koolitaja . "\n\n" . " Nimi: " . $nimi . "\n" . "  Email: " . $email . "\n" . "   Telefon: " . $telf . "\n" . "    Soovitud kuupäev (aaaa-kk-pp): " . $kuupaev . "\n\n" . "Märked: " . $marked;
    $msg2 = '<b>Hea</b> ' . $nimi . "\n\n" . "Täname Teid koolitusele broneerimast, teatame Teile registreeringu kinnitamisest 48h jooksul." . "\n\n" . "Teie Beauty Factory";

    mail($admin_email, "Koolitusele registreerumine", $msg, "From:" . $kodulehemail);
    mail($email, "Koolitusele registreerumine", $msg2, "From:" . $beauty);
    }
    ?>

At the moment there is only one word that I am trying to make in bold for the sake of testing. But when I get it working I will start editing it more and I want to echo a javascript function in the php if statement.

I have tried using single quotes, double quotes and the:

nl2br(htmlentities($msg2));

None of it works

  • What is the expected result of `echo "";`? – Brian Ray Mar 12 '15 at 12:46
  • 4
    And what is your question ? – Benjamin Lucas Mar 12 '15 at 12:47
  • See http://stackoverflow.com/q/12693093/2126792 – pschueller Mar 12 '15 at 12:54
  • is your file extension `.html` or `.php`?? – Nishant Solanki Mar 12 '15 at 12:58
  • file extension is .php. And the result for the success() script should be a javascript function that checks the form fields and creates a div for 3,5sec and then destroys it –  Mar 12 '15 at 14:25
  • @BenjaminLucas my question is: How can I use html in php ? Is there something I am missing ? The fail is .php, the mail() function is working properly, I receive an e-mail from the webpage and so does the client. But I can not use any html in the , it just writes it out, I need it to fulfill my commands ! :D –  Mar 12 '15 at 14:51

3 Answers3

0

Here is a sample example of how to use html tags in php:

<?php
 var $name = "xyz";
 var $email = "xyz@gmail.com";

 echo '<table border="1" style="width:20%">';
 echo '<tr><th>UserName</th><th>Email</th></tr><tr><td>';

 echo $name."<br>";
 echo '</td><td>';
 echo $email."<br>";
 echo '</td></tr></table>';

?>

This is basic php and html table format example,you can follow this for write html tags.

RaMeSh
  • 2,682
  • 2
  • 15
  • 31
0

The message you send is not interpreted as HTML. The default header of the mail function is text/plain.

If you want your customers to see the bold text, you must specify the content-type as HTML in the message header.

<?php
    // Set the content type of the email to HTML (and UTF-8)
    $header  = 'Content-type: text/html; charset=utf-8' . "\r\n";

    // Add the from field
    $header .= 'From: ' . $beauty . "\r\n";

    // Send email
    mail ($email, "Koolitusele registreerumine", $msg2, $header);
?>

However you will not be able to use Javascript as it is intepreted client side. PHP does not interpret Javascript, and most of the mail clients will not execute Javascript for obvious security reasons.

Slagt
  • 499
  • 2
  • 10
0

The problem was that the function mail() had a default content of text/plain, just needed the $header to make text/html. Thanks guys for your quick answers !