开发者

Zend Mailer error "From header set twice"

开发者 https://www.devze.com 2023-02-18 02:55 出处:网络
My question in based on Zend Mail I have a class that extends Zend Mail. Basically it is supposed to send two different mails to users upon registration.

My question in based on Zend Mail

I have a class that extends Zend Mail. Basically it is supposed to send two different mails to users upon registration.

It has two functions sendRegistrationMail and sendActivationMail and both methods use the same transport initiallized in constructor.

Calling the two functions sendRegistrationMail works but the second one gives the error: **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','s开发者_高级运维sl'=>'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)
                     {

                     }          
    } 
}
?>


Use clearFrom() to clear your headers during every iteration, if you really must use the same Zend_Mail object for a single iteration:

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

The error itself is pretty self-explanatory: you are calling setFrom() more than once, which is not needed. Most likely this is being caused by having instantiated the Zend_Mail object outside of an iteration and calling setFrom() from within this iteration.

0

精彩评论

暂无评论...
验证码 换一张
取 消