简体   繁体   English

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

[英]How to receive email attachments using php?

I'm trying to retrieve email and attachments in cpanel email. 我正在尝试检索cpanel电子邮件中的电子邮件和附件。 Emails are being retrieved correctly, however I cannot retrieve the attachments. 电子邮件已正确检索,但是我无法检索附件。 What am I doing wrong? 我究竟做错了什么?

My source code: 我的源代码:

$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
foreach($emails as $email_number) {
  $structure = imap_fetchstructure($inbox,$email_number);
}

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

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

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