Zend_Mail::setSubject PHP Method

setSubject() public method

Sets the subject of the message
public setSubject ( string $subject ) : Zend_Mail
$subject string
return Zend_Mail Provides fluent interface
    public function setSubject($subject)
    {
        if ($this->_subject === null) {
            $subject = $this->_filterOther($subject);
            $this->_subject = $this->_encodeHeader($subject);
            $this->_storeHeader('Subject', $this->_subject);
        } else {
            /**
             * @see Zend_Mail_Exception
             */
            require_once 'Zend/Mail/Exception.php';
            throw new Zend_Mail_Exception('Subject set twice');
        }
        return $this;
    }

Usage Example

Example #1
0
 public function saveFiles($fileArray)
 {
     if (empty($fileArray)) {
         return array();
     }
     // Init connection
     $this->initConnection();
     $savedFiles = array();
     @ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     @ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $charset = "utf-8";
     #$charset = "iso-8859-1";
     $mail = new Zend_Mail($charset);
     $setReturnPath = Mage::getStoreConfig('system/smtp/set_return_path');
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getDestination()->getEmailSender();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig('system/smtp/return_path_email');
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     if ($returnPathEmail !== null) {
         $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
         Zend_Mail::setDefaultTransport($mailTransport);
     }
     $mail->setFrom($this->getDestination()->getEmailSender(), $this->getDestination()->getEmailSender());
     foreach (explode(",", $this->getDestination()->getEmailRecipient()) as $email) {
         if ($charset === "utf-8") {
             $mail->addTo($email, '=?utf-8?B?' . base64_encode($email) . '?=');
         } else {
             $mail->addTo($email, $email);
         }
     }
     foreach ($fileArray as $filename => $data) {
         if ($this->getDestination()->getEmailAttachFiles()) {
             $attachment = $mail->createAttachment($data);
             $attachment->filename = $filename;
         }
         $savedFiles[] = $filename;
     }
     #$mail->setSubject($this->_replaceVariables($this->getDestination()->getEmailSubject(), $firstFileContent));
     if ($charset === "utf-8") {
         $mail->setSubject('=?utf-8?B?' . base64_encode($this->_replaceVariables($this->getDestination()->getEmailSubject(), implode("\n\n", $fileArray))) . '?=');
     } else {
         $mail->setSubject($this->_replaceVariables($this->getDestination()->getEmailSubject(), implode("\n\n", $fileArray)));
     }
     $mail->setBodyText(strip_tags($this->_replaceVariables($this->getDestination()->getEmailBody(), implode("\n\n", $fileArray))));
     $mail->setBodyHtml($this->_replaceVariables($this->getDestination()->getEmailBody(), implode("\n\n", $fileArray)));
     try {
         $mail->send(Mage::helper('xtcore/utils')->getEmailTransport());
     } catch (Exception $e) {
         $this->getTestResult()->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('Error while sending email: %s', $e->getMessage()));
         return false;
     }
     return $savedFiles;
 }
All Usage Examples Of Zend_Mail::setSubject