我试图从本地主机发送邮件。 但是我无法从本地主机发送邮件 所以有人能告诉我如何重新配置我的xampp从本地主机发送邮件


当前回答

您可以测试发送邮件在您的PC没有互联网

你应该使用剪纸这个简单的应用程序来测试发送邮件。你不需要配置任何东西。

只需运行它,并尝试测试发送邮件:

test_sendmail.php

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>

你会看到这个:

我希望你今天过得愉快。 你可以在Youtube上找到我的更多教程

欢呼!

其他回答

您必须为此定义一个SMTP服务器和端口。除了从实时主机发送邮件。

这是一个有用的链接。

注意:该端口应未使用。请小心点,Some 像Skype这样的应用程序使用默认端口和阻止 发送邮件。

根据我的个人经验,我发现与Vikas Dwivedi非常相似的答案会很好地工作。

步骤1 (php.ini文件)

在php.ini文件xampp\php\php.ini。更改设置如下:

 extension=php_openssl.dll
 [mail function]
 sendmail_path =":\xampp7\sendmail\sendmail.exe -t"
 mail.add_x_header=On

通过put关闭邮件函数下的其他变量;在他们面前。例如;smtp_port = 25

步骤2 (sendmail.ini文件)

在sendmail.ini位于xampp\sendmail\semdmail.ini更改为 后:

 smtp_server=smtp.gmail.com
 smtp_port=465
 smtp_ssl=auto
 auth_username=address@gmail.com
 auth_password=YourPassword

步骤3(代码)

创建一个php文件,并使用以下命令:

 <?php
    mail($to, "subject", "body", "From: ".$from);
 ?>

请注意

为了重新加载php.ini,您需要重新启动apache。 你需要在https://myaccount.google.com/u/1/security激活谷歌不太安全的应用程序访问 使用管理员权限运行Xampp可能会有所帮助。

您可以测试发送邮件在您的PC没有互联网

你应该使用剪纸这个简单的应用程序来测试发送邮件。你不需要配置任何东西。

只需运行它,并尝试测试发送邮件:

test_sendmail.php

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>

你会看到这个:

我希望你今天过得愉快。 你可以在Youtube上找到我的更多教程

欢呼!

在XAMPP v3.2.1中,出于测试目的,您可以在XAMPP/mailoutput中看到XAMPP发送的电子邮件。就我在Windows 8上的情况而言,这不需要任何额外的配置,是测试电子邮件的简单解决方案

我尝试了许多方法从XAMPP Localhost发送邮件,但由于XAMPP没有SSL证书,我的电子邮件请求被Gmail或类似的SMTP服务提供商阻止。

然后我使用MailHog本地smtp服务器,你需要做的就是运行它。 Localhost:1025是SMTP服务器, Localhost:8025是邮件服务器,在那里您可以检查您发送的电子邮件。

这是我的代码:

    require_once "src/PHPMailer.php";
    require_once "src/SMTP.php";
    require_once "src/Exception.php";

    $mail = new PHPMailer\PHPMailer\PHPMailer();

      //Server settings
    $mail->SMTPDebug = 3;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'localhost';                    // Set the SMTP server to send through
    $mail->Port       = 1025;                                    // TCP port to connect to
    // $mail->Username   = '';                     // SMTP username
    // $mail->Password   = '';                               // SMTP password
    // $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    // $mail->SMTPSecure = 'tls';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted

    //Recipients
    $mail->setFrom('testtoo@testto.com', 'Mailer');
    $mail->addAddress('testtoo@webbamail.com', 'Joe User');     // Add a recipient

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }

MailHog Github Repository链接