1<?php 2 3use \Tx\Mailer; 4use \Tx\Mailer\SMTP; 5use \Tx\Mailer\Message; 6use \Tx\Mailer\Exceptions\SMTPException; 7use \Monolog\Logger; 8 9class MailerTest extends TestCase { 10 11 protected $smtp; 12 protected $message; 13 14 public function setup(){ 15 $this->smtp = new SMTP(new Logger('SMTP')); 16 $this->message = new Message(); 17 } 18 19 public function testSMTP(){ 20 $this->smtp 21 ->setServer('smtp.ym.163.com', 25) 22 ->setAuth('bot@ym.txthinking.com', ''); // email, password 23 24 $this->message 25 ->setFrom('Tom', 'bot@ym.txthinking.com') // your name, your email 26 ->setFakeFrom('heelo', 'bot@hello.com') // a fake name, a fake email 27 ->addTo('Cloud', 'cloud@txthinking.com') 28 ->setSubject('Test SMTP ' . time()) 29 ->setBody('<h1>for test</h1>') 30 ->addAttachment('host', '/etc/hosts'); 31 32 $status = $this->smtp->send($this->message); 33 $this->assertTrue($status); 34 } 35 36 public function testSend(){ 37 $status = (new Mailer(new Logger('Mailer'))) 38 ->setServer('smtp.ym.163.com', 25) 39 ->setAuth('bot@ym.txthinking.com', '') // email, password 40 ->setFrom('Tom', 'bot@ym.txthinking.com') // your name, your email 41 ->setFakeFrom('张全蛋', 'zhangquandan@hello.com') // a fake name, a fake email 42 ->addTo('Cloud', 'cloud@txthinking.com') 43 ->setSubject('hello '. time()) 44 ->setBody('Hi, boy') 45 ->addAttachment('host', '/etc/hosts') 46 ->send(); 47 $this->assertTrue($status); 48 } 49 50} 51 52