php 从本地主机发送邮件
问题描述:
我是 php 新手.我试图使用此代码从 php 发送邮件.
I am new at php. I was trying to send mail from php using this code.
<?php
$to = 'sohil@gmail.com';
$subject = 'The subject';
$message = 'hello';
$headers = 'From: sohil@yahoo.in' . "
" .
'Reply-To: receiver@yahoo.in' . "
" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
我在 php.ini 中更改了设置
I have change settings in 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
&在 sendmail.ini 中
& in 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
现在代码运行成功,但我没有收到任何邮件.
Now code runs successfully but I am not getting any mail.
答
您必须更改 php.ini 文件:
You must change the php.ini file:
[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
如果设置了 localhost,它将不起作用,因此请更改您的邮件服务器.
It won't work if localhost is set, for that reason change to your mail server.