0

I'm am sending an email via the php code below, which sends an email template to the users emails address. However the email sends with all the HTML tags still visible and not in effect.

$fh = fopen('templates/customer.eml','r');

        $emailContents = fread($fh, filesize('templates/customer.eml'));
        $emailContents = str_replace(":name:", $person->first . " " . $person->last, $emailContents);
        $emailContents = str_replace(":meeting_name:", $meeting->name, $emailContents);
        $emailContents = str_replace(":chair:", $chair->first . " " . $chair->last, $emailContents);

        fclose($fh);

        $header = "FROM: [email protected]\r\n";
        $header = "MIME-Version: 1.0\r\n";
        $header.="Content-type: text/html; charset: utf8\r\n";
        mail($person->email , "Meeting Request", $emailContents, "FROM: [email protected]");

And below is the email template file that I am using for the content:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <p>
            Dear :name:,<br />
            You have been invited to <em>:meeting_name:</em> chaired by :chair:.
        </p>

        <p>
            Main text of the email will go here<sup>*</sup>.
        </p>
        <p>
            Thankfully
        </p>
        <p>
            User
        </p>
    </body>
</html>
1
  • You don't read the $header variable. You are only appending to it. Commented May 9, 2013 at 10:27

1 Answer 1

1

You're not passing the headers into the mail function. Try:

$header = "FROM: [email protected]\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .="Content-type: text/html; charset: utf8\r\n";
mail($person->email , "Meeting Request", $emailContents, $header);

Try these headers instead

$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=utf8' . "\r\n";
$header .= 'From: [email protected]' . "\r\n";
mail($person->email , "Meeting Request", $emailContents, $header);
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry about that my mistake. I have updated the $header into the mail function. However I now don't receive and an email?
Thanks for posting that code, it worked :) Really appreciate your help. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.