繁体   English   中英

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

[英]Upload a file to server sent by email

关于通过电子邮件上传文件,我有一个一般性的问题,因为我根本不知道是否可以这样做。

我有一个安装了Wordpress的共享网站空间。 我们希望增强我们的用户通过电子邮件(.pdf,.doc等)上传文件,发送到特定电子邮件地址的能力。

该文件是否可以被Wordpress识别并不重要,这些文件也可以由我自己的.php-script上传到特定的文件夹中。

一般有可能吗?

当我在网上搜索该问题时,我只是找到了反向解决方案(文件上传发生时通过电子邮件通知)。

我已经做过几次了,总是很痛苦。 您还应该不时登录邮箱进行检查。 另外,请记住,您将收到垃圾邮件,格式错误的电子邮件,并在那里答复所有电子邮件,因此请对此进行说明。

还可以对电子邮件主体进行解码,因为它有百万种口味,还带有嵌入式图形,因此很有趣。

这就是我用来监视具有基于文本的警报的邮箱的功能。

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

}

它还不完整,但是至少在弄清楚如何连接到电子邮件服务器上的邮箱之后,您才能使用消息正文

暂无
暂无

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

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