Swift_Attachment::fromPath PHP Method

fromPath() public static method

Create a new Attachment from a filesystem path.
public static fromPath ( string $path, string $contentType = null ) : Swift_Mime_Attachment
$path string
$contentType string optional
return Swift_Mime_Attachment
    public static function fromPath($path, $contentType = null)
    {
        return self::newInstance()->setFile(new Swift_ByteStream_FileByteStream($path), $contentType);
    }

Usage Example

Exemplo n.º 1
0
 public function sendMail()
 {
     $transport = Swift_SmtpTransport::newInstance($this->instance, $this->smtp_port);
     $transport->setUsername($this->username);
     $transport->setPassword($this->user_password);
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $message->setFrom($this->setFrom);
     $message->setTo($this->setTo);
     $message->setSubject($this->subject);
     $message->setBody($this->setBody, 'text/html', 'utf-8');
     if (!empty($this->setfilepath)) {
         $message->attach(Swift_Attachment::fromPath($this->setfilepath)->setFilename($this->aliasname));
     }
     /*try{
     	   if($mailer->send($message)){
     		   return true;
     	   }
     	 }
     	 catch (Swift_ConnectionException $e){
     		//echo 'There was a problem communicating with SMTP: ' . $e->getMessage();
     		return false;
     	 }*/
     return $mailer->send($message);
 }
All Usage Examples Of Swift_Attachment::fromPath