Email Zend Mailer错误“;从页眉设置两次“;

Email Zend Mailer错误“;从页眉设置两次“;,email,zend-framework,zend-mail,Email,Zend Framework,Zend Mail,我的问题基于Zend Mail 我有一个扩展Zend Mail的类。基本上,它应该在注册时向用户发送两封不同的邮件 它有两个函数sendRegistrationMail和sendActivationMail,这两个方法使用在构造函数中初始化的相同传输 调用这两个函数sendRegistrationMail可以工作,但第二个函数会出现错误:**From Header Set两次** class Mailer_Register_SendMail extends Zend_Mail { pu

我的问题基于Zend Mail

我有一个扩展Zend Mail的类。基本上,它应该在注册时向用户发送两封不同的邮件

它有两个函数sendRegistrationMail和sendActivationMail,这两个方法使用在构造函数中初始化的相同传输

调用这两个函数sendRegistrationMail可以工作,但第二个函数会出现错误:
**From Header Set两次**
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)
                     {

                     }          
    } 
}
?>
class Mailer\u Register\u SendMail扩展了Zend\u Mail
{
公共$\u配置;
公共交通;;
公共电子邮件;
来自电子邮件的公共美元;
public$\u fromFullName;
公共功能(电子邮件)
{
父项::_构造();
$this->_config=array('auth'=>'login','ssl'=>'tls','username'=>“$email”,'password'=>'12345678','port'=>'25');
$this->\u transport=new Zend\u Mail\u transport\u Smtp('127.0.0.1',$this->\u config);
$this->_email=$email;
$this->_fromEmail=”administrator@rta.com";
$this->\u fromFullName=“RTAsys.com”;
}
公共函数sendRegistrationMail()
{
$emailmessage=“欢迎使用Atanik授权
”。 “您将很快收到一封单独的激活邮件”

”; $fromemail=$this->\u fromemail; $fromfullname=$this->\u fromfullname; $to=$this->\u电子邮件; $subject=“欢迎来到RTA”; $this->setBodyHtml($emailmessage); $this->setFrom($fromemail,$fromfullname); $this->addTo($to); $this->setSubject($subject); 试一试{ $this->send($this->\u传输); } 捕获(Zend_邮件_传输_例外$ex) { } } 公共函数sendActivationMail() { $subjectActivation=“激活您的Angaza帐户”; $emailActivationMessage=“感谢您抽出时间加入Atanik 授权请单击下面的链接立即激活您的帐户 http://localhost/RTAsys/public/Account/activate?email=“$this->\u电子邮件; $fromActivationEmail=$this->\u fromEmail; $fromActivationFullName=$this->\u fromFullName; $to=$this->\u电子邮件; $this->setBodyText($emailActivationMessage); $this->setFrom($fromActivationEmail,$fromActivationFullName); $this->addTo($to); $this->setSubject($subjectActivation); 尝试 { $this->send($this->\u传输); } 捕获(Zend_邮件_传输_例外$ex) { } } } ?>
如果在每次迭代中确实必须使用同一Zend_Mail对象,请使用
clearFrom()
在每次迭代中清除标题:

$mail = new Zend_Mail();
foreach ($users as $key => $user) {
    $mail->clearFrom();
    $mail->setFrom('foo@bar');
    // do some more stuff
}

错误本身是不言自明的:您多次调用
setFrom()
,这是不需要的。这很可能是由于在迭代之外实例化了
Zend_Mail
对象,并在此迭代中调用了
setFrom()

显然我不清楚您的答案,因为我还在学习,我的类扩展了Zend_Mail。第一个函数是ok,我做了一些事情,比如$this->setfrom(),$this->setBody..,然后我做了$this->send($transport)…所以在发送之后我要清除所有这些。我的第二个函数几乎是相似的。我appreciate@jamon你在问问题吗?Rotterveel,我已经附上了我的简单代码,因为即使在clearFrom之后,我仍然不断地出现错误。你能assist@jamon,我没有看到你在任何地方调用clearFrom()。请再次阅读我的答案:如果应用正确,它将解决问题。@jamon只需添加$this->clearFrom();在sendRegistrationMail()的末尾