php从localhost发送邮件

Soh*_*sai 15 php email

我是php新手.我试图使用此代码从php发送邮件.

<?php

    $to      = 'sohil@gmail.com';
    $subject = 'The subject';
    $message = 'hello';
    $headers = 'From: sohil@yahoo.in' . "\r\n" .
        'Reply-To: receiver@yahoo.in' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

?>
Run Code Online (Sandbox Code Playgroud)

我在php.ini中更改了设置

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = sohil@gmail.com
Run Code Online (Sandbox Code Playgroud)

&在sendmail.ini中

# A freemail service example
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from sohil@gmail.com
auth on
user sohil@gmail.com
password xxxxxxxxx

# Set a default account
account default : Gmail
Run Code Online (Sandbox Code Playgroud)

现在代码运行成功,但我没有收到任何邮件.

K C*_*oud 1

该功能无法在您的本地主机上运行,​​因为 locahost 不能用作 SMTP 服务器,请将您的内容上传到安装了 SMTP 的有效服务器,然后进行邮件调用。