简体   繁体   English

将文件上传到通过电子邮件发送的服务器

[英]Upload a file to server sent by email

I have a general question regarding a file upload via email, as I don't know if this is possible at all. 关于通过电子邮件上传文件,我有一个一般性的问题,因为我根本不知道是否可以这样做。

I have a shared webspace with Wordpress installed on it. 我有一个安装了Wordpress的共享网站空间。 We want to enhance our users to upload files via email (.pdf, .doc, etc.), send to a specific email address. 我们希望增强我们的用户通过电子邮件(.pdf,.doc等)上传文件,发送到特定电子邮件地址的能力。

It doesn't matter if the file is recognized by Wordpress, the files could also just be uploaded by my own .php-script to a specific folder. 该文件是否可以被Wordpress识别并不重要,这些文件也可以由我自己的.php-script上传到特定的文件夹中。

Is this in general possible? 一般有可能吗?

When I search the web for this question, I just find reverse solutions (email notification when a file upload happens). 当我在网上搜索该问题时,我只是找到了反向解决方案(文件上传发生时通过电子邮件通知)。

I have done it a few times, and is always kind of a pain. 我已经做过几次了,总是很痛苦。 you should also log into the mailbox once in awhile to check on it. 您还应该不时登录邮箱进行检查。 Also, remember you will have spam, bad formatted emails, reply all emails in there so account for that. 另外,请记住,您将收到垃圾邮件,格式错误的电子邮件,并在那里答复所有电子邮件,因此请对此进行说明。

also fun decoding the email body as it comes in a million flavors, with embedded graphics as well. 还可以对电子邮件主体进行解码,因为它有百万种口味,还带有嵌入式图形,因此很有趣。

This is what I used to monitor a mailbox that had text based alerts. 这就是我用来监视具有基于文本的警报的邮箱的功能。

 class someEmailClass

 function inbox() {
    if( DEBUG) $GLOBALS['log']->Info( __CLASS__ .'.'. __FUNCTION__ .'()' );

    $this->msg_cnt = imap_num_msg($this->conn);
    $in = array();

    imap_headers( $this->conn); // to boost performance somehow

    $emails_to_fetch = $this->batchSize;
    if( $this->batchSize > $this->msg_cnt) 
// if fewer inbox items than batch size
    {
        $emails_to_fetch = $this->msg_cnt;
    }

    for($i = 1; $i <= $emails_to_fetch; $i++) {
        $email = array(
            'index'     => $i,
            'header'    => imap_headerinfo($this->conn, $i),
            'structure' => imap_fetchstructure($this->conn, $i)
        );

        $body = imap_fetchbody( $this->conn, $i, "1.1");
        if ($body == "") {
            $body = imap_fetchbody( $this->conn, $i, "1");
        }
        $email['body'] = $body;
        $email['body2'] = self::email_body_decode( $body, (int)$email['structure']->encoding );

        $in[] = $email;

    }

    $this->inbox = $in;

    $this->Errors = imap_errors();
}

    public static function email_body_decode( $data, $code =0)
{
    switch( $code){
//            case 0:
//                return imap_utf7_decode($data);
        case 1:
            return imap_utf8($data);
        case 3:
            return imap_base64($data);
        case 4:
            return imap_qprint($data);
        default:
            return $data;
    }
}

// http://www.php.net/manual/en/function.imap-open.php
function connect_debug()
{
    try {
        $this->conn = (imap_open("{mail.domain.com:993/imap/notls/ssl/novalidate-cert}INBOX", <user>, <pass>));
        if( $this->conn == false) {
            $err = 'Could not connect to email server ['. imap_last_error() .']';
            $this->Errors[] = $err;
            throw new \Exception( $err);
        }

    }
    catch( \Exception $ex){
        if( DEBUG) $GLOBALS['log']->Error( $ex );
        throw $ex;
    }
}

}

it is not complete, but will let you play with the message body at least after you figure out how to connect to the mailbox on the email server 它还不完整,但是至少在弄清楚如何连接到电子邮件服务器上的邮箱之后,您才能使用消息正文

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

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