邮件功能不会发送电子邮件.错误 [英] Mail function wont send eMail. ERROR

查看:71
本文介绍了邮件功能不会发送电子邮件.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我现在尝试从3天开始解决此问题,但似乎找不到问题.

I think i tried to fix this issue fr 3 days now and cant seem to find the problem.

我使用XAMPP并使用以下代码:

I use XAMPP and use this code:

<?php

$to = "carl.j.97@live.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "carl.j.97@live.com";
$headers = "From: $from";
$res= mail($to,$subject,$message,$headers);
echo " $res Mail Sent.";
?>

当我进入该页面时,出现错误消息:

when i enter that page i get an error that says:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set(

我在xampp中的php.init文件如下:

My php.init file in xampp are as follow:

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

那是我所有的代码.

推荐答案

如果您在XAMPP或在本地主机上运行的其他程序上运行此程序,请在Google上搜索所需的设置,以使电子邮件服务正常工作.您需要编辑一些文件并更改一些端口/客户端名称.

If you run this on XAMPP or anoher program that runs on localhost, search on Google for the settings you need to get email service working. You need to edit some files and change some ports/client names.

您只需要修改2个ini文件:php.ini和sendmail.ini

you only have to modify 2 ini files: php.ini and sendmail.ini

1)在php.ini(c:/xampp/php/php.ini)中查找邮件功能>> [邮件功能]

1)look for mail function in php.ini(c:/xampp/php/php.ini)>>[mail function]

更改以下内容:

SMTP=smtp.gmail.com

smtp_port=587


sendmail_from = from@gmail.com

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

注意:确保为sendmail_oath指定的路径有效.在我的情况下,该路径在C中.保存更改.

NOTE: ensure that the path you specify for sendmail_oath is valid.In my case it is in C. SAVE your changes.

2)接下来修改sendmail.ini(c:/xampp/sendmail/sendmail.ini)如下所示评论汞

2) next modify sendmail.ini(c:/xampp/sendmail/sendmail.ini) comment the mercury as shown below

# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off

# A freemail service example
#account Hotmail
#tls on
#tls_certcheck off
#host smtp.live.com
#from [exampleuser]@hotmail.com
#auth on
#user [exampleuser]@hotmail.com
#password [examplepassword]

然后粘贴以下行:

account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from x@gmail.com
auth on
user x@gmail.com
password x

port 587

# Set a default account
account default : Gmail

再次保存您的更改.

使用下面的代码测试其是否正常工作!

Use the code below to test if it's working!

<?php
$subject="Test mail";
$to="someone@whatever.com";
$body="This is a test mail";
if (mail($to,$subject,$body))
echo "Mail sent successfully!";
else
echo"Mail not sent!";
?>

请注意,在上述配置中,发件人应使用gmail电子邮件服务,对于收件人,任何电子邮件服务都可以使用.

NOTE in the above configuration the sender should use gmail email service,for the recipient any email service will do.

这篇关于邮件功能不会发送电子邮件.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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