【发布时间】:2013-08-19 17:27:24
【问题描述】:
我是 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);
?>
我在 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 中
# 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
现在代码运行成功,但我没有收到任何邮件。
【问题讨论】:
-
您必须在本地主机上安装邮件服务器。 PHPMailer
-
@Bora:我认为可以添加 gmail 或 yahoo smtp 邮件服务器。不是吗?
-
或使用远程smtp服务器,如GMAIL
-
您的代码看起来不错,但如果不在 localhost 上安装邮件服务器,它将无法在 localhost 上运行
-
gmail使用tls,可以配置默认邮件功能使用
tls吗?