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


当前回答

你必须在你的服务器上配置SMTP。你可以通过谷歌免费使用G Suite SMTP:

<?php

$mail = new PHPMailer(true);

// Send mail using Gmail
if($send_using_gmail){
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 465; // set the SMTP port for the GMAIL server
    $mail->Username = "your-gmail-account@gmail.com"; // GMAIL username
    $mail->Password = "your-gmail-password"; // GMAIL password
}

// Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";

try{
    $mail->Send();
    echo "Success!";
} catch(Exception $e){
    // Something went bad
    echo "Fail :(";
}

?>

点击这里阅读更多关于PHPMailer的信息。

其他回答

我花了一个多小时才搞定。对于每个人都有同样的问题,所有的建议张贴不工作:你必须重新启动Apache在你的XAMPP inrerface!只是重新启动XAMPP行不通!!

在本地主机或本地服务器上发送电子邮件非常简单

注意:我使用的测试邮件服务器软件在Windows 7 64bit安装Xampp

只需下载测试邮件服务器工具,并根据其网站上测试邮件服务器工具的说明进行安装

现在您只需要更改php.ini文件下的两行

找到[mail function]并删除前面的分号;smtp = localhost sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

您不需要更改任何其他内容,但如果您仍然没有收到电子邮件,则检查SMTP端口,端口号必须相同。

以上方法是针对Xampp软件提供的默认设置。

你必须在你的服务器上配置SMTP。你可以通过谷歌免费使用G Suite SMTP:

<?php

$mail = new PHPMailer(true);

// Send mail using Gmail
if($send_using_gmail){
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 465; // set the SMTP port for the GMAIL server
    $mail->Username = "your-gmail-account@gmail.com"; // GMAIL username
    $mail->Password = "your-gmail-password"; // GMAIL password
}

// Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";

try{
    $mail->Send();
    echo "Success!";
} catch(Exception $e){
    // Something went bad
    echo "Fail :(";
}

?>

点击这里阅读更多关于PHPMailer的信息。

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

这是一个有用的链接。

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

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