• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Html emails by php

Hi i have a question about php mail functions. I work allot with regular text. But not i want to send email with html code. I try allot in different way and gmail every time get massage as plain text. Can any one help me how i can make it.

The sample of working code will be better.
1 Solution
Neil_BradleyWeb UX/UI DeveloperCommented:
The code show below will send an email to the address in the "to" field. Basically you would POST the information from your html contact form to a php page containing the code below (just make sure your form  fields names  are "name",  "email", " phone" and "message".
$to = "youremail@yourdomain.com";
                        $subject = "Form Submission from Website";
                        $msg="Name: " . $_POST['name'] ."\n";
                        $msg.="Email: " . $_POST['email'] ."\n";
                        $msg.="Phone Number: " . $_POST['phone'] ."\n";
                        $msg.="Message: " . $_POST['message'] ."\n";
                        $headers = "From: " . $_POST['email'] . "\r\n" .
                        "Reply-To: ".$_POST['email'] . "\r\n" .
                        'X-Mailer: PHP/' . phpversion();
                        mail($to, $subject, $msg, $headers);
Marco GasiFreelancerCommented:
You can use attached class (TemplateMailer.class.php) this way:


$template_folder = '../templates/';//where you store normal html files to email saved as file.tpl.html

$temp = new TemplateMailer();
$temp->preparemail($template_folder . 'name_of_your_file.tpl.html');
$sent = $temp->send($destmail, $mailadres1, "Email subject", '');


Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Marco GasiFreelancerCommented:
Oooops, forgot the file
I think that PHPMailer class is what you are looking for.


Website: http://phpmailer.worxware.com/
$mail = new PHPMailer();

$mail->FromName="My site's mailer";

$mail->Subject = "Test 1";

$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
$mail->AltBody="This is text only alternative body.";


Open in new window

As I also suggest for PHPMailer.

Use PHPMailer with authentication to send email and to avoid going to span.

$mail->Host     = "mail.somethign.com";
$mail->Mailer   = "smtp";
$mail->SMTPAuth = "true";
$mail->Username = "*********";
$mail->Password = "******";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now