使用phpmailer通过电子邮件发送正文内容

时间:2012-11-08 08:04:52

标签: php

我正在尝试在jobbersbase中的phpmailer()中添加文件。

但我没有得到如何正确添加

我正在使用这样的,但它仅邮寄$ mailer-> Body =($ data ['apply_location1']);,我的意思是在$ mailer-> AltBody = $ msg之上;声明。但我想通过邮件发送所有信息。

public function MailApplyOnline($data)
{
    $mailer = $this->getConfiguredMailer();
    $subject = $this->emailTranslator->GetApplyOnlineSubject($data);

    $msg = $data['apply_msg'];

    $msg .= $this->emailTranslator->GetApplyOnlineMsg($_SERVER['HTTP_REFERER']);

    $mailer->SetFrom($data['apply_email'], $data['apply_name']);
    $mailer->AddAddress($data['company_email'], $data['company_name']);
    $mailer->Subject = $subject;
    $mailer->Body = $this->nl2br($msg);
    $mailer->Body = ($data['apply_company']);
    $mailer->Body = ($data['apply_contact']);
    $mailer->Body = ($data['apply_title']);
    $mailer->Body = ($data['apply_location']);
    $mailer->Body = ($data['apply_location1']);
    $mailer->AltBody = $msg;

    if ($data['attachment_filename'] != '')
    {
        $mailer->AddAttachment($data['attachment_path'], $data['attachment_filename']);
    }

    if ($mailer->Send())
    {
        return true;
    }
    else
    {
        return false;
    }
} 

1 个答案:

答案 0 :(得分:0)

创建一个局部变量$ body并继续附加您需要为正文内容添加的内容。

$body = "";
$body .= $this->nl2br($msg) . "<br/>";
$body .= ($data['apply_company']) . "<br/>";
$body .= ($data['apply_contact']) . "<br/>";
$body .= ($data['apply_title']) . "<br/>";
$body .= ($data['apply_location']) . "<br/>";
$body .= ($data['apply_location1']) . "<br/>";

$mailer->Body = $body;

您的代码失败的原因是您继续覆盖$ mailer-&gt; Body。