Question

I`m sending two letters by Swift:

$mail = Mailer::getInstance($oData->Subject);
                    $mail->setTo($oData->Email, $oData->Recipient)
                        ->setBody($body , 'text/html')
                        ->setFrom(array('some@gmail.com' => 'some.com'));
                    $mail->setAttach($_FILES["Resume"]["tmp_name"]);

                    if (isset($aContent['Recipient']) && !empty($aContent['Recipient']['Value'])) {
                        $mail->setTo($aContent['Recipient']['Value']);
                    }

                    if ($mail->send()) {
                        $mail2 = Mailer::getInstance("Thanks!");
                        $mail2->setFrom(array('some@gmail.com' => 'some.com'))
                            ->setTo(array($aContent['Email']['Value']))
                            ->setBody($thanksEnding , 'text/html')
                            ->setSubject("Wonderful Subj");
                        if ($mail2->send()) {
                            $this->show->success = TRUE;
                            $this->show->message = __("Message sent.");
                        }
                    } else {
                        $this->show->message = __("Error.");
                    }

and both of letters have attachments. How can I make attachment to first letter only?

Was it helpful?

Solution

getInstance()

Looks like either factory or singleton pattern. It looks more like a singleton pattern and therefore you'll get the SAME instance of the object when calling.

So $mail and $mail2 are probably the same instances.

Use better design patterns and make fresh instances using new Mailer().

OTHER TIPS

calling $mailer2->setAttach(null); before sending it may do the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top