为什么此SMTP电子邮件发件人不起作用?

时间:2019-10-18 13:28:31

标签: php sockets email smtp

我正在尝试从php服务器发送电子邮件。我不知道为什么这段代码不发送电子邮件。

laravel Mail :: to(....)对我不起作用,所以我尝试创建自己的函数。

$socket = socket_create (AF_INET, SOCK_STREAM , getprotobyname('tcp'));

 $sent = 0;
 if(socket_connect($socket, $domain,25))
 {
      $sent = socket_write($socket,"ehlo " . $domain,strlen("ehlo" . $domain));

      if($sent==false)
      {
          dd("Error1");
      }

      $sent = socket_write($socket,"MAIL FROM:<" . $txt->from[0]['address'] . ">",strlen("MAIL FROM:<" . $txt->from[0]['address'] . ">"));
      if($sent==false)
      {
           dd("Error2");
      }

      $sent = socket_write($socket,"RCPT TO:<" . $txt->to[0]['address'] . ">",strlen("RCPT TO:<" . $txt->to[0]['address'] . ">"));
       if($sent==false)
       {
           dd("Error3");
       }

      $sent = socket_write($socket,"DATA",strlen("DATA"));
      if($sent==false)
      {
           dd("Error4");
      }

      $inp = "FROM: <" . $txt->from[0]['address'] . ">\n" . "TO: <" . $txt->to[0]['address'] . ">\n" . "Subject: " . $txt->subject . "\nDate: " . date("D, j M o H:i:s O",time()) . "\n\n" . $txt->textView . "\n\n.";
      $sent = socket_write($socket,$inp,strlen($inp));
      if($sent==false)
      {
           dd("Error5");
      }

      $sent = socket_write($socket,"QUIT",strlen("QUIT"));
      if($sent==false)
      {
           dd("Error6");
      }

 }
 socket_close($socket);

代码运行没有错误,但是电子邮件没有收到我

输出形式dd(发送inp1,2,...):

"ehlo trashmail.com"

"MAIL FROM:<myserver@test.com>"

"RCPT TO:<test45rg@trashmail.com>"

"DATA"

"""
FROM: <myserver@test.com>


TO: <test45rg@trashmail.com>


Subject: Your Test account - activation


Date: Fri, 18 Oct 2019 13:20:34 +0000



<html>


<head>


    <title>Test activation mail</title>


</head>



<body>


<h2>Welcome to Test UserName!</h2>


<br/>


Your registered email is test45rg@trashmail.com , Please click on the link below to activate your Test account


<br/>


<a href="http://127.0.0.1:8080/user/verify/LE41uFAuq4A3ACcBnwFzCfmhcNmcaLJ068zxnC9O">Verify Email</a>


</body>


</html>

.

"""

"QUIT"

0 个答案:

没有答案