为什么我的邮件功能在XAMMP中不起作用? [英] Why is my mail function not working in XAMMP?

查看:168
本文介绍了为什么我的邮件功能在XAMMP中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用XAMPP进行这项工作,由于某些原因邮件功能不起作用,这里是我的代码。我在MAC和我的php.ini在etc文件夹,我没有sendmail文件夹。

I have been trying to make this work using XAMPP and for some reason the mail function does not work, here is my code. I'm in a MAC and my php.ini in the etc folder and I don't have the sendmail folder.

$_POST['email'];

$result = mail('someEmail@gmail.com', 'This is a Subject', 'This is the body of the email', 'From: $email');
echo $result ? 'Sent' : 'Error';


推荐答案

你不能直接从localhost。一种方法是将您的代码移动到公共服务器或使用某些SMTP服务器(如果要在本地主机上工作)。
您应该对这两个文件进行一些更改,例如xampp\php\php.ini 和 xampp\sendmail\sendmail.ini

You can`t directly from localhost. One way is to move your code to public server or using some SMTP server if you want to work on your localhost. You should make some changes to those two files xampp\php\php.ini and xampp\sendmail\sendmail.ini

php.ini 文件搜索并查找[邮件功能],使其看起来像这样

in php.ini file search and find [mail function] and make it look like this

SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = YOUR_MAIL@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

ini 确保它看起来像这样

now in sendmail.ini make sure it look like this

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
auth_username=YOUR_MAIL@gmail.com
auth_password=YOUR_MAIL_PASS
force_sender=YOUR_MAIL@gmail.com

现在确保在 php.ini

extension=php_openssl.dll

被取消注释。另外请确保在以下行注释如果有另一个sendmail_path

is uncommented. Also make sure to comment following line if there is another sendmail_path

sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

如果一切正常,您将使用google gmail从本地主机发送邮件。因此,接收者将在 FROM 字段

If everything is OK your will be sending mail from localhost using google gmail. So the receiver will see your gmail in FROM field

这篇关于为什么我的邮件功能在XAMMP中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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