简体   繁体   English

Yeti CRM不会使用PHPMailer附加文件

[英]Yeti CRM will not attach files using PHPMailer

I am using a form in the Yeti CRM that allows the user to view a document then gives them the option to email said document. 我在Yeti CRM中使用一个表单,允许用户查看文档,然后为他们提供通过电子邮件发送文档的选项。 It is using PHPMailer but I cannot get it to attach the document. 它使用的是PHPMailer,但我无法将其附加到文档中。 All other fields are responding to edits (To, From, Subject, Body) but nothing is attaching. 所有其他字段都响应编辑(To,From,Subject,Body)但没有附加任何内容。 Error logs do not throw an error. 错误日志不会引发错误。

I have tried directly linking a file that I know exists but still no luck. 我试过直接链接一个我知道但仍然没有运气的文件。 Can anyone see in the code below where I am not actually attaching the document? 任何人都可以在下面的代码中看到我实际上没有附加文档?

Here is the PHP function 这是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();
}

} }

This is the js file that builds the params 这是构建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));
        }
    });
};

}); });

And the form 形式

<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>

The email sends fine with all of the fields except the attachment. 电子邮件可以发送除附件之外的所有字段。 I haven't used PHP in six years so suffice to say I'm a little rusty. 我已经六年没用PHP了,所以我说我有点生疏了。 Can anyone see why the attachment is not attaching? 任何人都可以看到为什么附件没有附加?

With a little help from @Synchro I have solved my issue. 在@Synchro的帮助下,我解决了我的问题。 My PHP file was not calling the attachment correctly. 我的PHP文件没有正确调用附件。 The field is an array and I was trying to make it a string. 该字段是一个数组,我试图使它成为一个字符串。 Once I set $attachment equal to the values in the array built in PHPMailer it sent without issue. 一旦我将$ attachment设置为等于PHPMailer中构建的数组中的值,它就会毫无问题地发送。

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

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

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