Solved

Html emails by php

Posted on 2010-09-23
6
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Accepted Solution

by:
jkratzer earned 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

More and more people are using the enhanced small form-factor pluggable (SFP+) tranceivers, and speed is of utmost importance. Testing of speeds are critical to ensure that the devices will meet the speed requirements. There are some testing challen…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

751 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