无法从本地主机使用php发送电子邮件

时间:2020-08-04 16:51:17

标签: php xampp localhost sendmail.exe

我正在尝试使用php向帐户发送电子邮件,并且我正在运行xampp服务器,因此我正在使用localhost发送电子邮件。我整天都在尝试这样做,并且在这里没有找到答案就检查了许多帖子。 我尝试过的:

PHP.INI (此函数中的其他每一行都用;注释)

 [mail function]
    SMTP=smtp.gmail.com
    smtp_port =465
    sendmail_from =vskentos1@gmail.com
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe" -t" 

SENDMAIL.INI (每行也用;注释)

[sendmail]

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

我也尝试过更改仍然无法使用的smtp_port = 587,并且在将端口更改为;smtp_ssl=auto时,我还将SENDMAIL.INI中的smtp_ssl = tls更改为587没有结果,所以 我回到上面已经包含的;smtp_ssl=autosmpt_port=465。 每当我对文件进行更改时,我都会重新启动xampp服务器。我还允许使用不太安全的应用 通过配置我的Google帐户的安全性来进行访问。 我的php代码,用于通过localhost运行文件时发送电子邮件(可以,但是永远不会发送电子邮件)

<?php
    
    $to      = "vskentos2@gmail.com";
    $subject = "Test email";
    $message = "hello";

    mail($to,$subject,$message);

    if(mail($to, $subject, $message)){
        echo "email was sent to $to"; //this line is printed when I run localhost 
    }else{
        echo "fail";
    } 

    
?>
    

非常感谢您的帮助。谢谢你。

0 个答案:

没有答案