Solved

Html emails by php

Posted on 2010-09-23
6
313 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 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 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