我试图从本地主机发送邮件。 但是我无法从本地主机发送邮件 所以有人能告诉我如何重新配置我的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行不通!!

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

这是一个有用的链接。

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

除了所有的答案,请注意sendmail.ini文件中:

auth_password = this-is-Not-your-Gmail-password

由于新的谷歌安全问题,您应该按照以下步骤为此目的设置应用程序密码:

在安全选项卡中转到https://accounts.google.com/ 使用任何可用选项打开两步验证 回到安全选项卡(在同一部分下,两步验证最初被发现),并创建App-password(在选择app下拉菜单中,您可以选择“其他”)

最后,请注意,如果您只是使用一个应用程序,而不是自己编写php代码,则可能需要将Sendmail设置为首选选项。

作为管理员运行XAMPP还应该解决任何文件访问问题。

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

你必须在你的服务器上配置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的信息。