Programmer's Reference Guide

導入

SMTP 経由での送信

SMTP 経由でメールを送信するには、 send() をコールする前に Zend_Mail_Transport_Smtp を作成し、それを Zend_Mail に登録しなければなりません。スクリプト内でその後に Zend_Mail::send() がコールされると、 SMTP による転送が使用されます。

例1 SMTP によるメールの送信

  1. $tr = new Zend_Mail_Transport_Smtp('mail.example.com');
  2. Zend_Mail::setDefaultTransport($tr);

setDefaultTransport() メソッドや Zend_Mail_Transport_Smtp のコンストラクタは、 そんなに大げさなものではありません。この 2 行をスクリプトのセットアップ時 (config.inc など) に設定し、スクリプト内での Zend_Mail の挙動を決めることができます。 これにより、メール送信を SMTP 経由で行うのか » mail() を使用するのか、 そしてどのメールサーバを使用するのかなどといった設定情報を、 アプリケーションから分離できます。


導入

Comments

$tr = new Zend_Mail_Transport_Smtp('out.telenet.be');
$mail->setFrom('a@gmail.com', 'Server');
$mail->addTo($to, 'a@gmail.com');
$mail->setSubject($subject);
$mail->send();
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setBodyText($body);
public function send()
{
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'username@gmail.com', 'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

$mail = new Zend_Mail();
if (strtolower($this->getType()) == 'html')
$mail->setBodyHtml($this->getBody());
}
else {
$mail->setBodyText($this->getBody());
}

$mail
->setFrom($this->getFromEmail(), $this->getFromName())
->addTo($this->getToEmail(), $this->getToName())
->setSubject($this->getSubject());

$mail->send($transport);

return $this;
}
test
thanks this is really helpful
I am a new learner of ZendFramework,and I have less knowledge about php. Now I want to write a program for sending mail, I don't how to start. asking for help.

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual