Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Content-type to Pear Mail

Tags:

php

i'm assuming setting a content type of text/html format income emails to the default font style and size of the clients/users machine. User Pear Mail how would I add in a content type. All the examples I've send only show adding content-type with mime attachments.

Also if there is another way to make and incoming email default to users mail clients font style and size, I'd like to know.

would like to add

$headers  = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

current mail code

$from = "[email protected]";
$to = $SendTo;
$subject = "Contact : " . $uxGlobalLocation;
$body = $Bodycopy;
$host = "mail.set.co";
$username = "[email protected]";
$password = "empty00";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
header ('Location: /');
exit();
}

EDIT Possible answer

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=iso-8859-1',
'MIME-Version' => '1.0');
like image 595
acctman Avatar asked Jan 16 '23 18:01

acctman


1 Answers

This works. It took me forever to figure out the last item in the $headers array must have \r\n\r\n

<?php
require_once "Mail.php";
$from = "Web Master <[email protected]>";
$replyto = "Education Dept. <[email protected]>";
$to = "<[email protected]>";
$subject = "Test email using PHP SMTP";
$body = "<p>Test HTML</p><p>This is a test email message</p>";

$host = "smtp.example.com";
$username = "[email protected]";
$password = "****************";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject,
  'Reply-To' => $replyto,
  'MIME-Version' => "1.0",
  'Content-type' => "text/html; charset=iso-8859-1\r\n\r\n");

$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Message successfully sent!</p>");
}
?>
like image 139
dmgd Avatar answered Jan 25 '23 15:01

dmgd