如何配置XAMPP从localhost php发送电子邮件


how to configure XAMPP to send email from localhost php

我试图使用php从本地主机发送电子邮件,但失败了代码如下

<?php
$to= "fahmie.art98@gmail.com";
$subject = "this is test";
$messages= "this is message test, congrats, your success"
if( mail($to, $subject, $messages) ) {
echo "success guys";
}
else{
echo "failed guys";
};
?>

如何解决这些问题?我用的是linux。以及如何配置我的XAMPP在本地主机上发送电子邮件?

你可以配置C:'xampp'php'php.ini和C:'xampp' sendmail'sendmail.ini让gmail发送邮件。

在C:'xampp'php'php.ini中找到extension=php_openssl.dll并删除该行开头的分号以使SSL适用于gmail for localhost

在php.ini文件中找到[mail function]并修改

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "'"C:'xampp'sendmail'sendmail.exe'" -t"

现在打开C:'xampp'sendmail'sendmail.ini。将sendmail.ini中的所有现有代码替换为以下代码

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=your-gmail@gmail.com
auth_password=your-gmail-password
force_sender=your-mail-gmail-id@gmail.com

现在你已经完成了!!输入你的gmail账号