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

时间:2016-09-17 01:06:17

标签: php linux email xampp localhost

我试图使用php从localhost发送电子邮件,但失败了 像这样的代码

<?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以在localhost上发送电子邮件?

1 个答案:

答案 0 :(得分:1)

您可以配置C:\ xampp \ php \ php.ini和c:\ xampp \ sendmail \ sendmail.ini以便gmail发送邮件。

在C:\ xampp \ php \ php.ini中找到extension = php_openssl.dll并从该行的开头删除分号,以使SSL为ghost 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帐户