1

I'm forced to use IMAP to send e-mail because my e-mail provider annoyingly doesn't support SMTP.

So I looked up how to send e-mail over IMAP in PHP.

I found this: https://www.php.net/manual/en/function.imap-mail.php

imap_mail ( string $to , string $subject , string $message [, string $additional_headers = null [, string $cc = null [, string $bcc = null [, string $rpath = null ]]]] ) : bool

All the other imap_* functions have a parameter to specify which IMAP connection to use. This function does not.

How does imap_mail know which "IMAP handle" to use?

  • Can you send mail via IMAP? https://stackoverflow.com/questions/1627596/how-can-you-send-mail-using-imap – Progrock Dec 31 '20 at 01:05
  • In General, IMAP cannot be used to _send_ mail (some rarely used extensions aside). PHP's mail() command (and by extension imap_mail) rely on a `sendmail` program or similar existing (or possibly SMTP?), they do not send by IMAP. – Max Dec 31 '20 at 01:12

1 Answers1

1

Unlike other imap_* functions, the imap_mail is a function which is similar to mail() but it allows sending of emails with correct handling of Cc and Bcc receivers.

For the other imap_* functions, they acts on an already established IMAP handle ($imap_stream), that's why these imap_* functions will require an $imap_stream to work on. (For example, imap_open will return a $imap_stream)

Imagine that your PHP is working on two or more $imap_streams, then the system must know which imap_stream you are referring to if you execute say the imap_check function.

Ken Lee
  • 6,985
  • 3
  • 10
  • 29
  • Well... um... so how do I do it? How do I send the e-mail? If it's nothing but a wrapper for `mail()`, it's worthless and has nothing to do with IMAP? – user14756437 Dec 31 '20 at 00:48
  • So how do I send e-mail via IMAP from PHP? I have PHPMailer, but it seems to only be relevant for SMTP. I've previously only had to send e-mail via SMTP. I thought it was a standard. I barely knew that you even COULD send e-mails over IMAP... But now I *have* to. – user14756437 Dec 31 '20 at 00:56
  • For your information, the protocol for sending email out is SMTP. The IMAP protocol is just one which specify the way how the mails in a particular mailbox is handled. (You may study the difference between POP3 and IMAP protocols.). That's why when you add an email account in an email client say Outlook / Thunderbird, you will need to enter the SMTP settings which is for outgoing mail. – Ken Lee Dec 31 '20 at 00:59