PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 16, 2018 9:02 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Aug 19, 2009 12:43 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Oct 24, 2006 1:07 pm
Posts: 118
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


Top
 Profile  
 
PostPosted: Sat Aug 22, 2009 2:08 pm 
Offline
Forum Commoner
User avatar

Joined: Tue Aug 18, 2009 12:39 am
Posts: 58
Location: Chennai city, India
Hi,
I guess, it will work for u fine. In ur mail option, add these lines,

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


Then input the message in html format,

For ex:
Syntax: [ Download ] [ Hide ]
$message  = "
<table width='200' border='1'>
  <tr>
    <td>hi</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
 
</table>"
;


Top
 Profile  
 
PostPosted: Sun Aug 23, 2009 6:10 am 
Offline
Forum Contributor
User avatar

Joined: Tue Oct 24, 2006 1:07 pm
Posts: 118
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


Top
 Profile  
 
PostPosted: Sun Aug 23, 2009 7:45 am 
Offline
Forum Commoner
User avatar

Joined: Tue Aug 18, 2009 12:39 am
Posts: 58
Location: Chennai city, India
Hello, send me one example. I will work it and give u back.


Top
 Profile  
 
PostPosted: Sun Aug 23, 2009 9:34 am 
Offline
Forum Contributor
User avatar

Joined: Tue Oct 24, 2006 1:07 pm
Posts: 118
hello sorry for the late response
here is a simple basic template file
Syntax: [ Download ] [ Hide ]
 
<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>
 

here is my sender class TheMailer.class.php
Syntax: [ Download ] [ Hide ]
 
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:
File comment: just in case you wanted the image too
32_Ad-Aware.png
32_Ad-Aware.png [ 1.71 KiB | Viewed 3881 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group