pedia-learning

ورود

گذرواژه‌تان را فراموش کرده‌اید؟

ثبت نام

ثبت نام
انجمن عمومی گسترش فناوری آگو

اگر اولین بار از انجمن بازدید می کنید برای دسترسی کامل به انجمن عضو شوید بعد عضویت قادر به ارسال مطلب و شرکت در بحث خواهید داشت

ارسال پاسخ 
 
امتیاز موضوع:
  • 0 رأی - میانگین امتیازات: 0
  • 1
  • 2
  • 3
  • 4
  • 5
کلاس آماده : خواندن ایمیل ها با php
12-08-2013, 10:27 PM
ارسال: #1
کلاس آماده : خواندن ایمیل ها با php
سلام

با استفاده از کلاس زیر میتونید ایمیل هایی که توی inbox دارین رو بخونین.این کلاس ممکنه جاهایی کاربرد داشته باشه مثلا اینکه یک ایمیل بسازید و بخواید به صورت خودکار ایمیلهایی که بهش میاد رو پردازش کنید و در جوابش چیزی رو ارسال کنید.

کد php:
<?php

class Email_reader {

    
// imap server connection
    
public $conn;

    
// inbox storage and inbox message count
    
private $inbox;
    private 
$msg_cnt;

    
// email login credentials
    
private $server 'yourserver.com';
    private 
$user   'email@yourserver.com';
    private 
$pass   'yourpassword';
    private 
$port   143// adjust according to server settings

    // connect to the server and get the inbox emails
    
function __construct() {
        
$this->connect();
        
$this->inbox();
    }

    
// close the server connection
    
function close() {
        
$this->inbox = array();
        
$this->msg_cnt 0;
        
imap_close($this->conn);
    }

    
// open the server connection
    // the imap_open function parameters will need to be changed for the particular server
    // these are laid out to connect to a Dreamhost IMAP server
    
function connect() {
        
$this->conn imap_open('{'.$this->server.'/notls}'$this->user$this->pass);
    }

    
// move the message to a new folder
    
function move($msg_index$folder='INBOX.Processed') {
        
// move on server
        
imap_mail_move($this->conn$msg_index$folder);
        
imap_expunge($this->conn);

        
// re-read the inbox
        
$this->inbox();
    }

    
// get a specific message (1 = first email, 2 = second email, etc.)
    
function get($msg_index=NULL) {
        if (
count($this->inbox) <= 0) {
            return array();
        }

        elseif ( ! 
is_null($msg_index) && isset($this->inbox[$msg_index])) {
            return 
$this->inbox[$msg_index];
        }

        return 
$this->inbox[0];
    }

 
    
// read the inbox
    
function inbox() {
        
$this->msg_cnt imap_num_msg($this->conn);
        
$in = array();
        for(
$i 1$i <= $this->msg_cnt$i++) {
            
$in[] = array(
                
'index'     => $i,
                
'header'    => imap_headerinfo($this->conn$i),
                
'body'      => imap_body($this->conn$i),
                
'structure' => imap_fetchstructure($this->conn$i)
            );
        }

        
$this->inbox $in;
    }
}

?>

دقت کنید که متغیر های $server , $user , $pass رو تغییر بدین.متغیر $port رو هم باید مطابق با تنظیمات سرور تون باید تغییر بدین.

منبع : دیدن لینک ها برای شما امکان پذیر نیست. لطفا ثبت نام کنید یا وارد حساب خود شوید تا بتوانید لینک ها را ببینید.

موفق باشیدبازدید : ۱۲۹۸
Incoming search terms:

خواندن inbox ایمیل به وسیله php
اموزش خواندن ایمیل ها در php
خواندن ایمیل php
خواندن میل با imap در php
کد php برای ساخت inbox
نقل قول این ارسال در یک پاسخ
ارسال پاسخ 


پرش به انجمن:


کاربرانِ درحال بازدید از این موضوع: 1 مهمان


Persian Translation by MyBBIran.com - Ver: 4.1
Powered by MyBB, © 2002-2024 MyBB Group.
Theme designed by Marvel (Sidebar created by Yaldaram - Yaldaram.com)
Theme Translation by Mt Edition