PHPMAILER在附件中发送电子邮件

时间:2016-07-05 06:05:13

标签: php html phpmailer html-email

<?php    
include('phpmailer.php');
class Mail extends PhpMailer
{
    // Set default variables for all new objects
    public $From     = 'noreply@domain.com';
    public $FromName = SITETITLE;
    public $Host     = 'smtp.gmail.com';
    public $Mailer   = 'isSMTP';
    public $SMTPAuth = true;
    public $Username = 'email@gmail.com';
    public $Password = 'password';
    public $SMTPSecure = 'ssl';
    public $WordWrap = 75;

    public function subject($subject)
    {
        $this->Subject = $subject;
    }

    public function body($body)
    {
        $this->Body = $body;
    }

    public function send()
    {
        $this->AltBody = strip_tags(stripslashes($this->Body))."\n\n";
        $this->AltBody = str_replace("&nbsp;", "\n\n", $this->AltBody);
        return parent::send();
    }
}

我正在将此代码用于Email.php文件并且它可以正常但它以正常形式发送附件中的邮件... Email Attachment Showing in Email

Email Attachment Output

以下是我将其用于验证目的的链接。

http://monthlyreport.ultimatefreehost.in

在index.php我正在使用像这样

 //send email
            $to = $_POST['email'];
            $subject = "Registration Confirmation";
            $body = "<p>Thank you for registering at demo site.</p>
            <p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a></p>
            <p>Regards Site Admin</p>";

            $mail = new Mail();
            $mail->setFrom(SITEEMAIL);
            $mail->addAddress($to);
            $mail->subject($subject);
            $mail->body($body);
            $mail->send();

            //redirect to index page
            header('Location: index.php?action=joined');
            exit;

1 个答案:

答案 0 :(得分:-1)

您的函数应返回值。

return $this->Body = $body;的末尾使用body(),同样也可以在其他功能中使用{{1}}。

相关问题