[英]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.