PHPMailer(SetFrom和AddReplyTo)

时间:2016-06-23 12:14:44

标签: php phpmailer

代码:

class email extends main{
    function email($to, $to_name, $subject, $message, $type, $schoolTitle, $schoolEmail, $attachments){
        $this->to = $to;    
        $this->to_name = $to_name;
        $this->subject = $subject;
        $this->message = $message;
        $this->type = $type;
        $this->schoolTitle = $schoolTitle;
        $this->schoolEmail = $schoolEmail;
        $this->attachments = $attachments;
    }
    function connect(){
        require_once PLUGINS.'PHPMailer-20160322/PHPMailerAutoload.php';
        $this->mail = new PHPMailer;
        $this->mail->isSMTP();
        $this->mail->SMTPDebug = 0;
        $this->mail->Debugoutput = 'html';
        $this->mail->Host = "**********";
        $this->mail->Port = **;
        $this->mail->SMTPAuth = true;
        $this->mail->SMTPSecure = 'tls';  
        //$mail->Sender="************";
        $this->mail->Username = "**************";
        $this->mail->Password = "**************";

    }
    function sendSingle(){
    //this is used in the bulk emailer when the connect it called so we can send multiple emails from 1 connection
    $this->mail->addAddress($this->to, $this->to_name);
    $this->mail->Subject = $this->subject;
    $this->mail->msgHTML($this->getMessage());
    $this->mail->AltBody = strip_tags($this->message);
    $this->mail->setFrom($this->schoolEmail, $this->schoolTitle);
    $this->mail->AddReplyTo($this->schoolEmail, $this->schoolTitle);                    
    foreach($this->attachments as $item){           
        $this->mail->addAttachment($item);
    }

    if (!$this->mail->send()) {
        return false;
    } else {
        return true;
    }
}
}

我想要的结果:

我希望能够使用testEmailtestTitle

$this->schoolEmail= "chris.beckett@testing.co.uk";
$this->schoolTitle= "Chris Beckett";
$this->mail->setFrom($this->schoolEmail, $this->schoolTitle);
$this->mail->AddReplyTo($this->schoolEmail, $this->schoolTitle);

我尝试过的工作:

我不明白为什么testTitle有效,但当我尝试传入testEmail时,电子邮件不会发送或者会发送但是它不会有{{1}的参数1}}或from:

reply to:

调试信息显示它有效但电子邮件没有显示在我的收件箱中:

$this->schoolEmail= "chris.beckett@testing.co.uk";
$this->schoolTitle= "Chris Beckett";
$this->mail->setFrom('name@yourdomain.com', $this->schoolTitle);
$this->mail->AddReplyTo('name@yourdomain.com', $this->schoolTitle);

有人能解释我的错误吗?

0 个答案:

没有答案