I want to send email with 4 HTML attachments in it, each of the attachment have images.
The problems:
1. The images in the HTML attachments are missing. I already use the server path for images in the attachment (for example <img src='/server/img.jpg'>).
2. All the attachments are from Page 4 instead of from Page 1, Page 2, Page 3 and Page 4.
Is it possible to have images in HTML Attachment using the FileEmbedder plugin? Is there something wrong in my code so that all the attachments are from the last attachment?
I use PHP 4.3.9 and Swift 3.2.6.
Please help, Thanks!
Code: Select all
class CommissionMailer {
var $commission;
function CommissionMailer(){}
function mailNewCommission($commissionid) {
if(!empty($commissionid)) {
$this->commission = new CommissionForm();
$this->commission->id = $commissionid;
$details = $this->commission->getDetails();
$prefix = "<html><body>";
$suffix = "</body></html>";
$page1 = $prefix.$this->commission->getPage(1, $details, true).$suffix;
$page2 = $prefix.$this->commission->getPage(2, $details, true).$suffix;
$page3 = $prefix.$this->commission->getPage(3, $details, true).$suffix;
$page4 = $prefix.$this->commission->getPage(4, $details, true).$suffix;
$a1 = new Swift_Message_Attachment($page1,"commission-p1.html","text/html");
$a2 = new Swift_Message_Attachment($page2,"commission-p2.html","text/html");
$a3 = new Swift_Message_Attachment($page3,"commission-p3.html","text/html");
$a4 = new Swift_Message_Attachment($page4,"commission-p4.html","text/html");
$attachments = array();
array_push($attachments, $a1);
array_push($attachments, $a2);
array_push($attachments, $a3);
array_push($attachments, $a4);
$ss = new SwiftSend();
$message ="Please see Commission/Fee Request Forms attached.";
$subject = "[Commission/Fee Request] Submitted: ".$details['client_company'];
$requestor = new User();
$requestor->id = $details['receiverid'];
$requestor->getDetails();
$sendto = array($requestor->email);
$ss->sendWithAttachment($message, $subject, $sendto, $attachments);
}
}
}
class SwiftSend {
var $swift;
var $smtp;
function SwiftSend() {
$smtp_path = "localhost";
$this->smtp =& new Swift_Connection_SMTP($smtp_path, 25);
$this->swift =& new Swift($this->smtp);
$this->swift->attachPlugin(new Swift_Plugin_AntiFlood(50, 10), "anti-flood");
$this->swift->attachPlugin(new Swift_Plugin_FileEmbedder(), "file_embedder");
}
function sendWithAttachment($message, $subject, $arrayto=null, $attachments=null, $from='', $replyto='', $arraycc=null, $arraybcc=null) {
$this->swift->log->enable();
$this->swift->log->setMaxSize(1);
if(!empty($from)) $sender = $from;
else $sender = new Swift_Address("publisher@domain.com", "Intranet");
if(empty($replyto)) {
$replyto = new Swift_Address("nursita@domain.com", "Nursita");
}
$swiftmessage =& new Swift_Message();
$swiftmessage->attach(new Swift_Message_Part($message, 'text/html'));
$swiftmessage->setReplyTo($replyto);
$swiftmessage->setSubject($subject);
$recipients =& new Swift_RecipientList();
$recipients->addBcc($replyto);
if(is_array($arrayto) or is_email($arrayto)) {
$continue = false;
if(!is_null($arrayto) and count($arrayto) != 0) {
foreach(@$arrayto as $toemail) {
if((!empty($toemail) and is_email($toemail)) or is_a($toemail,"Swift_Address"))
$recipients->addTo($toemail);
}
$continue = true;
}
if(is_email($arrayto)) {
$recipients->addTo($arrayto);
$continue = true;
}
if($continue) {
if(!is_null($arraycc) and count($arraycc) != 0) {
foreach(@$arraycc as $ccemail) {
if(!empty($ccemail) or is_a($ccemail,"Swift_Address"))
$recipients->addCc($ccemail);
}
}
if(!is_null($arraybcc) and count($arraybcc) != 0) {
foreach(@$arraybcc as $bccemail) {
if(!empty($bccemail) or is_a($bccemail,"Swift_Address"))
$recipients->addBcc($bccemail);
}
}
if(!is_null($attachments) and count($attachments) != 0) {
foreach(@$attachments as $a) {
$swiftmessage->attach($a);
}
}
if ($this->swift->send($swiftmessage, $recipients, $sender))
return "Message sent";
else
return "<font color=red>Sorry, the system failed to send your email</font>.<br>Errors: ".$this->swift->log->dump();
$this->swift->disconnect();
}
}
$this->swift->log->disable();
}
}