Hello! guys i'm trying to build a mail solution that will actually send html mail from a template file with of course place holders for personalized emails.
I've been reading this version 4.0.4 and don't really see something like that.If this feature is not supported yet can you let me know the library you use to
achieve that kind of things.thanks for reading
Send Email from HTML Template.Help!
Moderators: Chris Corbyn, General Moderators
- mrvijayakumar
- Forum Commoner
- Posts: 58
- Joined: Tue Aug 18, 2009 12:39 am
- Location: Chennai city, India
- Contact:
Re: Send Email from HTML Template.Help!
Hi,
I guess, it will work for u fine. In ur mail option, add these lines,
For ex:
I guess, it will work for u fine. In ur mail option, add these lines,
Then input the message in html format,$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
For ex:
Code: Select all
$message = "
<table width='200' border='1'>
<tr>
<td>hi</td>
<td> </td>
<td> </td>
</tr>
</table>";Re: Send Email from HTML Template.Help!
Hello mrvijayakumar !
Thanks for reading my post and thanks for the answer.I was wondering if i've asked a stupid question since i got no reply.Actually what i was trying to do is to have a template html file which will have some images inside.The one you are suggesting is just easy even with images but i'm picking the html mail from a file say template.html .I could use file_get_contents to send the html mail if there is no images.But with images inside the file is not that obvious.Thanks for your help anyway
Thanks for reading my post and thanks for the answer.I was wondering if i've asked a stupid question since i got no reply.Actually what i was trying to do is to have a template html file which will have some images inside.The one you are suggesting is just easy even with images but i'm picking the html mail from a file say template.html .I could use file_get_contents to send the html mail if there is no images.But with images inside the file is not that obvious.Thanks for your help anyway
- mrvijayakumar
- Forum Commoner
- Posts: 58
- Joined: Tue Aug 18, 2009 12:39 am
- Location: Chennai city, India
- Contact:
Re: Send Email from HTML Template.Help!
Hello, send me one example. I will work it and give u back.
Re: Send Email from HTML Template.Help!
hello sorry for the late response
here is a simple basic template file
here is my sender class TheMailer.class.php
here is a simple basic template file
Code: Select all
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
</head>
<body>
<div style="border-width:10px;border-color:orange">
<table border='0' width='15'>
<tr bgcolor="#FFF999">
<td colspan='2'><img src="32_AdAware.png" alt='logo'/> Dear highjo ,this is to officially notify that there has been a xxxxx on your account. \n
The details of the transaction are :</td>
</tr>
<tr>
<td>test</td>
<td>test</td>
</tr>
</table>
</div>
</body>
</html>
Code: Select all
include_once 'swift_required.php';
class TheMailer {
private $mailer;
private $message;
function __construct($serverAddress, $portNumber, $mailSecurity, $servUserName, $servPassword, $senderDetails, $transportType) {
$trans = Swift_SmtpTransport::newInstance($serverAddress,$portNumber, $mailSecurity)
->setUsername($servUserName)
->setPassword($servPassword);
$this->mailer = Swift_Mailer::newInstance($trans);
//$sendDetails is an array
$this->message = Swift_Message::newInstance()
->setFrom($senderDetails);
}
public function sendMessage($username, $userEmailAddress, $themessage, $templatePath, $messageSubject) {
try {
$this->message->setTo($userEmailAddress)->setBody($themessage);
//not using the $templatePath for now.template path is hardcoded
//now how to add the image to the message object.I guess i cannot use the Swift_FIle anymore nor use any swift class inside the template
//file to create something like cid or Embedded object.so how?
$this->message->addPart(file_get_contents("template.html"),'text/html');
$this->message->setSubject($messageSubject);
echo $this->mailer->send($this->message);
} catch (Exception $ex)
{
echo "Error sending the message".$ex->getMessage();
}
}
}
}
- Attachments
-
- just in case you wanted the image too
- 32_Ad-Aware.png (1.71 KiB) Viewed 7093 times