Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Html emails by php

Posted on 2010-09-23
6
Medium Priority
?
324 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:umaxim
6 Comments
 
LVL 6

Accepted Solution

by:
jkratzer earned 2000 total points
ID: 33749798
0
 
LVL 5

Expert Comment

by:Neil_Bradley
ID: 33750174
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".
<?php
$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);
                        
                        ?>
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33751112
You can use attached class (TemplateMailer.class.php) this way:

<?php
include('../TemplateMailer.class.php');

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

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

?>

Cheers
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33751114
Oooops, forgot the file
TemplateMailer.class.zip
0
 
LVL 12

Expert Comment

by:Rok-Kralj
ID: 33761562
I think that PHPMailer class is what you are looking for.

$mail->IsHTML(true);

Website: http://phpmailer.worxware.com/
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();

$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";

$mail->AddAddress("email@example.com");
$mail->Subject = "Test 1";

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

$mail->Send();
?>

Open in new window

0
 
LVL 4

Expert Comment

by:spsenthil
ID: 33763295
As I also suggest for PHPMailer.

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

$mail->IsHTML(true);
$mail->IsSMTP();
$mail->Host     = "mail.somethign.com";
$mail->Mailer   = "smtp";
$mail->SMTPAuth = "true";
$mail->Username = "*********";
$mail->Password = "******";
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Beyond Tools A conversation I recently had with the DevOps manager of a major online retailer really made me think about DevOps monitoring tools (https://www.onpage.com/devops-incident-management-tool/). The manager and I discussed how sever…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question