php从本地主机发送邮件

我是新来的PHP我试图使用这个代码从php发送邮件.

<?php

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

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

?>

我有更改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 = sohildesai.xxxx@gmail.com

&安培;在sendmail.ini

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

# Set a default account
account default : Gmail

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

您必须更改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 = you@yourdomain

如果设置了本地主机,则将无法正常工作,因此更改为您的邮件服务器.

翻译自:https://stackoverflow.com/questions/18288007/php-send-mail-from-localhost

转载注明原文:php从本地主机发送邮件