Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Send Mail in HTML format

the mail() function

Moderators: macek, egami, gesf

Send Mail in HTML format

Postby aweklin » Thu Jun 21, 2012 3:16 am

Hello guys,

I want to be able to send mail in html format like the one below but I get the raw html in my mail.

include_once "Mail.php";

function isMailSent($from, $to, $subject, $body) {

$host = "mail.domain.com";
$username = "email@domain.com";
$password = "password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

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

// add to the body
$body = '<p><img src="/images/logo.png" /></p>' . $body . '<p>Thank you!</p>';

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

// check if mail was sent successfully
if (PEAR::isError($mail)) {
return "<p>" . $mail->getMessage() . "</p>";
} else {
return "<p>Message successfully sent!</p>";
}

} catch (Exception $e) {
return $e->getMessage();
}
}


Please help!
aweklin
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon May 14, 2012 1:48 am

Re: Send Mail in HTML format

Postby aweklin » Mon Jun 25, 2012 12:38 am

Got it solved by adding the following

$headers["From"] = $from;
$headers["To"] = $to;
$headers["Subject"] = $subject;
$headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = "8bit";

Thanks everybody.
aweklin
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon May 14, 2012 1:48 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.