php - detect if email is sent

后端 未结 7 1571
面向向阳花
面向向阳花 2020-12-09 18:49

Im building an automated newsletter, im kinda stuck with this problem. I need to know if the email was sent or not. Here is my code

 @$send = mail($emailReci         


        
7条回答
  •  悲&欢浪女
    2020-12-09 19:08

    Only for sake of completeness it should be mentioned that there is a way to send an email via PHP and to know whether it is really accepted by receiving MTA (which, again, doesn't mean it is delivered to user or discarded silently after SMTP handshake) or not.

    One could theoretically write an SMTP client purely in PHP, for example using built-in Stream functions like stream_socket_client in order to talk to receiving MTA via direct raw tcp connections formed in SMTP protocol requests and responses.

    General logic of issuing SMTP commands would be like:

    Of course, this is blatantly incomplete (experienced devs would notice that I wasn't neither listening nor parsing to SMTP responses I'd get). In order for this approach to be used serious re-inventing the wheel in PHP language has to be performed.

    How would this be used to detect if email is sent?

    Well, you would have at least 3 types of information:

    1. whether receiving host is alive and gets email messages at all
    2. whether you'r not bounced during handshake (SMTP 5xx responses class)
    3. whether you got SMTP 250 2.0.0 Ok after submitting message text

    Again, this is only for educational purposes, don't do this at home unless you're prepared to marry the project of developing standard-compliant SMTP client.

提交回复
热议问题