无法使用SMTP通过PHP发送电子邮件

无法使用SMTP通过PHP发送电子邮件,php,email,xampp,smtp,Php,Email,Xampp,Smtp,这是我的email.php文件: <?php $to = "someemail@gmail.com"; $from = "myemail@gmail.com"; $subject="Email"; $body="hi"; $headers = array( 'From' => $from, 'To' => $to, 'Subject' => $subject

这是我的email.php文件:

 <?php

    $to = "someemail@gmail.com";
    $from = "myemail@gmail.com";

    $subject="Email";
      $body="hi";  
    $headers = array(
        'From' => $from,
        'To' =>  $to,
        'Subject' => $subject
        );

             $smtp = Mail::factory('smtp', array(
                    'host' => 'ssl://smtp.gmail.com',
                    'port' => '465',
                    'auth' => true,
                    'username' => 'myemail@gmail.com',
                    'password' => 'password'
                ));
            $mail = $smtp->send( $to, $headers, $body);

            if (PEAR::isError($mail)) {
                echo('<p>' . $mail->getMessage() . '</p>');
            } else {
                echo('<p>Message successfully sent!</p>');
            }

?>      
我在Windows中使用XAMPP,这是我在php.ini文件中输入的内容:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 465
; For Win32 only.
sendmail_from = myemail@gmail.com

如果有人能帮我解决这个问题,我将不胜感激

我建议使用SwiftMailer使用不同的方法

您可以很容易地使用json文件获取组件,并查看其运行情况。

您在输入验证码后10分钟内登录,对吗?我不熟悉xampp。但是我希望您已经安装了php pear,并且mail.php在您的
require
语句中
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 465
; For Win32 only.
sendmail_from = myemail@gmail.com