How do you send email from an IMAP account using PHP?

I have a problem sending email via PHP / IMAP - and I don't know if this was because:

  • I misunderstand IMAP, or
  • Problem with my server

My application opens an IMAP connection with an email account to read messages in the inbox. He does it successfully. The problem is that I want to send messages from this account and display them in the send / send folder.

As far as I can tell, the PHP imap_mail () function has nothing to do with the IMAP stream that I am currently opening.

My code runs without error. However, the message never arrives at the recipient and never appears in my folder.

private function createHeaders() {
    return "MIME-Version: 1.0" . "\r\n" .
        "Content-type: text/html; charset=iso-8859-1" . "\r\n" .
        "From: " . $this->accountEmail . "\r\n";
}

private function notifyAdminForCompleteSet($urlToCompleteSet) {
    $message = "
        <p>
            In order to process the latest records, you must visit
            <a href='$urlToCompleteSet'>the website</a> and manually export the set.
        </p>
    ";

    try {
        imap_mail(
            $this->adminEmail,
            "Alert: Manual Export of Records Required",
            wordwrap($message, 70),
            $this->createHeaders()
        );
        echo("   ---> Admin notified via email!\n");
    }
    catch (Exception $e) {
        throw new Exception("Error in notifyAdminForCompleteSet()");
    }
}

, IMAP ... ?

, , "" , script? , .

+3
3

imap_mail - sendmail, mail. SMTP ( PHPMailer Swift Mailer), Sent imap_append.

, , imap_send . , SMTP- .

+5

, IMAP erorr imap_last_error(). , .

+1

Check the return value of your call on imap_mail. imap_maildoes not throw an exception on error, returns false.

In addition, you will need to copy the message to the sent folder yourself, imap_mailit will not do this for you.

0
source

Source: https://habr.com/ru/post/1781727/


All Articles