php 从本地主机发送邮件 [英] php send mail from localhost

查看:31
本文介绍了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.

这篇关于php 从本地主机发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆