繁体   English   中英

Yeti CRM不会使用PHPMailer附加文件

[英]Yeti CRM will not attach files using PHPMailer

我在Yeti CRM中使用一个表单,允许用户查看文档,然后为他们提供通过电子邮件发送文档的选项。 它使用的是PHPMailer,但我无法将其附加到文档中。 所有其他字段都响应编辑(To,From,Subject,Body)但没有附加任何内容。 错误日志不会引发错误。

我试过直接链接一个我知道但仍然没有运气的文件。 任何人都可以在下面的代码中看到我实际上没有附加文档?

这是PHP函数

public function process(\App\Request $request)
{
    $moduleName = $request->getModule();
    $recordId = $request->getInteger('record');
    $documentRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
    $currentUser = Users_Record_Model::getCurrentUserModel();

    $mails = $request->get('to');
    $message = $request->get('message');
    $from['email'] = $currentUser->get('email1');        
    $name = $currentUser->get('first_name') . " " . $currentUser->get('last_name');
    $from['name'] = $name;
    $file = $documentRecordModel->get('filename');
    $title = $documentRecordModel->get('notes_title') . substr($file, strrpos($file, "."));
    if (strpos($file, "\\\\") !== false) {
        $file = trim($file);
        $file = str_replace('\\\\', '\\', $file);
        $file = str_replace('\\', '/', $file);
        $file = str_replace(' ', '%20', $file);
        $file = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 
            "public_html" . DIRECTORY_SEPARATOR .
            "external" . 
            $file;            
        $attachment[$file] = $title;            
    } else {
        //this is a http type document, so just link straight to it.
        $message .= '<br />' . '<a href=' . $file . '>' . $title . '</a>';
    }

    if (count($mails) > 0) {
        $results[] = \App\Mailer::sendFromTemplate([
            'template' => 'ZcoSendPDFFile',
            'moduleName' => 'Documents',
            'recordId' => $recordId,
            'to' => $mails,
            'from' => $from,
            'message' => $message,
            'attachments' => $attachment, 
            //'smtp_id' => 2,
        ]);
    }
     $response = new Vtiger_Response();
 $response->setResult($results);
 $response->emit();
}

}

这是构建params的js文件

$(document).ready(function () {
var form = document.getElementById("emailDocument");
form.onsubmit = function (event) {
    event.preventDefault();
    let thisInstance = this;
    let fromEmail = $("#fromEmail").html();
    let toEmail = $("#toEmail").val();
    let message = $("#message").val();
    let recordId = getParameterByName("record");
    let attachment = $("#pdfAttach").html();
    let params = {
        'module': 'Documents',
        'action': 'ZcoEmailFile',
        'mode': 'process',
        'from': fromEmail,
        'to': toEmail,
        'message': message, 
        'record': recordId,
        'attachments': attachment
    };        
    $.post({
        url: "index.php",
        data: params,
        ContentType: "text/json",
        success: function() {
            alert('Email has been sent!');
        },
        beforeSend: function(xhr) {
            $("#submitEmail").attr("disabled", "disabled");
        },
        complete: function() {
            $("#submitEmail").removeAttr("disabled");
        },
        error: function(msg) {
            alert(JSON.stringify(msg));
        }
    });
};

});

形式

<form id="emailDocument">
        <div id="pdfAttach" value="{$FILENAME}" style=display:none;>{$FILENAME}</div>
        <div class="row pdfForm">
            <div class="col-md-5">
                <div class="toFrom">From:</div>
                <div><span id="fromEmail" class="ml-1">{$USER_MODEL->get('email1')}</span></div>
                <br />
                <div class="toFrom">To:</div>
                <div><input type="text" id="toEmail" value="{$CONTACT->get('email')}"></div>
                <br />
            </div>
            <div class="col-md-5" rowspan="2">
                Additional Message:
                <textarea type="text" id="message" rows="3" cols="50"></textarea></div>    
            <div class="col-md-2">
                <br />
                <input type="submit" value="Submit" id="submitEmail">
            </div>
        </div>
</form>

电子邮件可以发送除附件之外的所有字段。 我已经六年没用PHP了,所以我说我有点生疏了。 任何人都可以看到为什么附件没有附加?

在@Synchro的帮助下,我解决了我的问题。 我的PHP文件没有正确调用附件。 该字段是一个数组,我试图使它成为一个字符串。 一旦我将$ attachment设置为等于PHPMailer中构建的数组中的值,它就会毫无问题地发送。

代码添加: $attachment = array($path, $file, $name, $encoding, $type, false, $disposition, $name);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM