如何使用PHP接收电子邮件附件?

时间:2018-03-09 09:03:06

标签: php

我正在尝试在cpanel电子邮件中检索电子邮件和附件。正确检索电子邮件,但我无法检索附件。我究竟做错了什么?

我的源代码:

$emailAddress = "email@email.com" ; // Full email address
$emailPassword = "password";        // Email password
$domainURL = 'email.com';              // Your websites domain
$useHTTPS = true;

$inbox = imap_open('{'.$domainURL.':143/notls}INBOX',$emailAddress,$emailPassword) or die('Cannot connect to domain:' . imap_last_error());
   /* grab emails */
  $emails = imap_search($inbox,'UNSEEN');
  if($emails) {        


    /* put the newest emails on top */
    rsort($emails);

    /* for every email... */
    foreach($emails as $email_number) {

        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox, $email_number,0);
        $message = imap_fetchbody($inbox,$email_number,2);

        $header = imap_headerinfo($inbox, $email_number, 1);
        /* output the email header information */

        $subject_other= $overview[0]->subject;
        $sender_name_other= $overview[0]->from;
        $date_other=$overview[0]->date;
        $msg_to_other=$overview[0]->to;
        $msg_from_other = $header->from[0]->mailbox . "@" . $header->from[0]->host;
        $msg_msg_other = $message;

        //store to database email data

        mysqli_query($con,"insert into other(msg_to, msg_from, sender_name, subject, message, msg_date_time) values('$msg_to_other', '$msg_from_other', '$sender_name_other', '$subject_other', '$msg_msg_other', '$date_other')");             
     }


  } 

/* close the connection */
imap_close($inbox);
 // insert into other email in database

1 个答案:

答案 0 :(得分:0)

foreach($emails as $email_number) {
  $structure = imap_fetchstructure($inbox,$email_number);
}

http://php.net/manual/en/function.imap-fetchstructure.php