ngu*_*ria 4 email zend-framework zend-mail
我的问题基于Zend Mail
我有一个扩展Zend Mail的类.基本上它应该在注册时向用户发送两封不同的邮件.
它有两个函数sendRegistrationMail和sendActivationMail,两个方法都使用在构造函数中初始化的相同传输.
调用两个函数sendRegistrationMail可以工作,但第二个函数给出了错误: **From Header Set Twice**
class Mailer_Register_SendMail extends Zend_Mail
{
public $_config;
public $_transport;
public $_email;
public $_fromEmail;
public $_fromFullName;
public function __construct($email)
{
parent::__construct();
$this->_config=array('auth'=>'login','ssl'=>'tls','username'=>"$email",'password'=>'12345678','port'=>'25');
$this->_transport=new Zend_Mail_Transport_Smtp('127.0.0.1',$this->_config);
$this->_email=$email;
$this->_fromEmail="administrator@rta.com";
$this->_fromFullName="RTAsys.com";
}
public function sendRegistrationMail()
{
$emailmessage="<h3>Welcome to the Atanik Authorization</h3></br>".
"<p>You will soon receive your activation email as a separate message</p>";
$fromemail=$this->_fromEmail;
$fromfullname=$this->_fromFullName;
$to=$this->_email;
$subject="Welcome to RTA";
$this->setBodyHtml($emailmessage);
$this->setFrom($fromemail,$fromfullname);
$this->addTo($to);
$this->setSubject($subject);
try {
$this->send($this->_transport);
}
catch (Zend_Mail_Transport_Exception $ex)
{
}
}
public function sendActivationMail()
{
$subjectActivation="Activate Your Angaza Account";
$emailActivationMessage="Thank you for taking time to join Atanik
Authorization Please click the link below to activate your account now
http://localhost/RTAsys/public/Account/activate?email=".$this->_email;
$fromActivationEmail=$this->_fromEmail;
$fromActivationFullName=$this->_fromFullName;
$to=$this->_email;
$this->setBodyText($emailActivationMessage);
$this->setFrom($fromActivationEmail,$fromActivationFullName);
$this->addTo($to);
$this->setSubject($subjectActivation);
try
{
$this->send($this->_transport);
}
catch (Zend_Mail_Transport_Exception $ex)
{
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
使用clearFrom()每个迭代中清除您的头,如果你真的必须使用相同的Zend_Mail对象单次迭代:
$mail = new Zend_Mail();
foreach ($users as $key => $user) {
$mail->clearFrom();
$mail->setFrom('foo@bar');
// do some more stuff
}
Run Code Online (Sandbox Code Playgroud)
错误本身是不言自明的:你setFrom()不止一次打电话,这是不需要的.很可能这是因为Zend_Mail在迭代之外实例化对象并setFrom()在此迭代中调用.
| 归档时间: |
|
| 查看次数: |
4263 次 |
| 最近记录: |