-5

I want to display the HTML I wrote in the emails that are send out to customers and admin. Right now it's just showing all the html tags.

I have this code:

<?php 
if(isset($_POST['submit'])){
        $to = "myemail@myemail.com";
        $from       = $_POST['email_address'];
        $first_name = $_POST['first_name'];
        $last_name  = $_POST['last_name'];
        $address_street = $_POST['address_street'];
        $phone      = $_POST['mobile_no'];
        $customer_message = $_POST['textarea'];

        $subject  = "Spejl Blank - Klik en pris";

        $message  = "<html><body>";
        $message .= "<h1HELLO WORLD!</h1>";
        $message .= "</body></html>";
        $message .= "Du modtager her dit uforpligtende tilbud :)";
        $message .= "Din besked: " . $customer_message;

        $headers  = "From:" . $from;
        $headers2 = "From:" . $to;
        $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
        $headers  = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

        mail($to,$subject,$message,$message1,$headers);
        mail($from,$subject,$message,$message1,$headers2);

    }
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
RasmusGlenvig
  • 765
  • 6
  • 18

1 Answers1

1

This as per your original post https://stackoverflow.com/revisions/36426850/1

Here's the deal. Your code has a missing > for <h1HELLO WORLD!</h1> so that'll need to be changed to <h1>HELLO WORLD!</h1>.

Edit: Ah, now you edited that in now https://stackoverflow.com/revisions/36426850/2, yet the following still applies.

Then the "chain link" broke in $headers = "MIME-Version: 1.0" . "\r\n"; where there's a missing dot/concatenate.

$headers .= "MIME-Version: 1.0" . "\r\n";

Then you're using 5 parameters in the headers which won't work. There is a 5th for mail() but that's for something entirely different.

Read the manual on it:

You also on top of that, don't have anything assigned to $message1 yet that would be useless to use anyway.


Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Then the rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.


Edit:

Another thing is that you need to create new headers to get the other mail sent as HTML, and that is most likely why you said it wasn't sending as HTML.

Only the first mail sent will be HTML and not the second one. Consult one of my answers on Stack to do this https://stackoverflow.com/a/18382062/ and add new HTML headers for each of them, using different variables for each header just as you did for $headers2 and apply that to your code using the same way you used the HTML for $headers.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Thanks for your answer! I have just tried your changes but it still doesn't work. I have removed $message1 and i've added the dot before the "=" – RasmusGlenvig Apr 05 '16 at 13:04
  • @RasmusGlenvig You're welcome. Read the manual on `mail()` as per the link I gave you in my answer and follow it to a "T". – Funk Forty Niner Apr 05 '16 at 13:05
  • I will do, thanks a lot! – RasmusGlenvig Apr 05 '16 at 13:05
  • @RasmusGlenvig something else I noticed is that you need to move `$message .= " – Funk Forty Niner Apr 05 '16 at 13:06
  • @RasmusGlenvig another thing is that you need to create new headers to get the other mail sent as HTML, and that is most likely why you said it wasn't sending as HTML. Only the first mail sent will be HTML and not the second one. Consult one of my answers on Stack to do this http://stackoverflow.com/a/18382062/ – Funk Forty Niner Apr 05 '16 at 13:15