如何配置XAMPP从localhost发送邮件?

时间:2013-04-12 07:20:01

标签: php xampp

我正在尝试从localhost发送邮件。 但我无法从localhost发送邮件 所以任何人都可以告诉我如何重新配置​​我的xampp以从localhost发送邮件

13 个答案:

答案 0 :(得分:339)

您可以使用sendmail包从localhost发送邮件,在XAMPP中建立sendmail包。 因此,如果您正在使用XAMPP,那么您可以轻松地从localhost发送邮件。

例如,您可以为gmail配置C:\xampp\php\php.inic:\xampp\sendmail\sendmail.ini以发送邮件。

C:\xampp\php\php.ini中找到extension=php_openssl.dll并从该行的开头删除分号,以使SSL适用于本地主机的gmail。

在php.ini文件中找到[mail function]并更改

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

现在打开C:\xampp\sendmail\sendmail.ini。使用以下代码替换sendmail.ini中的所有现有代码

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

现在你已经完成了!!使用邮件功能创建php文件并从localhost发送邮件。

PS:不要忘记在上面的代码中替换 my-gmail-id my-gmail-password 。 另外,如果您从上面复制了设置,请不要忘记删除重复的密钥。例如,如果php.ini文件中有另一个 sendmail_path sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe",则注释后续行

另请记住使用XAMMP控制面板重新启动服务器,以使更改生效。

对于Gmail,请检查https://support.google.com/accounts/answer/6010255以允许从不太安全的应用访问。

  

通过Gmail从Linux发送电子邮件(带有sendmail包)   localhost请检查PHP+Ubuntu Send email using gmail form localhost

答案 1 :(得分:33)

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

答案 2 :(得分:23)

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

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

只需下载测试邮件服务器工具,然后按照其网站Test Mail Server Tool

上的说明进行安装

现在您只需更改php.ini文件

下的两行
  1. 查找[mail function]并删除;smtp = localhost
  2. 之前的半冒号
  3. sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
  4. 之前放置半结肠

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

    上述方法适用于Xampp软件提供的默认设置。

答案 3 :(得分:19)

您必须在服务器上配置SMTP。您可以免费使用Google的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 here

答案 4 :(得分:12)

您可以在没有互联网

的PC中测试发送邮件

你应该使用Papercut这个简单的应用来测试发送邮件。而且你不需要配置任何东西。

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

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);
?>

你会看到:

enter image description here

我希望你过得愉快。 您可以在 Youtube上找到我以获取更多教程Piseth Sok

振作!

答案 5 :(得分:5)

对于Windows 8上的人,如果你想这样做,我真的建议你阅读我发现的这个教程:http://yogeshchaugule.com/blog/2013/configure-sendmail-wamp

它不是由我写的,而是在将我的头撞到混凝土墙上2.5小时之后,没有让它与最奇怪的错误一起工作:

  • 连接超时。
  • 正常关闭连接。

我终于发现安装了https://www.stunnel.org/downloads.html和Stunnel的配置。它终于奏效了。

答案 6 :(得分:2)

根据我的亲身经历,我发现与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

通过在mail funciton之前放置;来关闭其他变量。例如;smtp_port=25

第2步(sendmail.ini文件)

在xampp \ sendmail \ semdmail.ini中的sendmail.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);
 ?>

通知

  • 您需要重新启动apache才能重新加载php.ini。
  • 您需要在https://myaccount.google.com/u/1/security中激活Google Less安全应用访问权限
  • 使用管理员权限运行Xampp可能会有所帮助。

答案 7 :(得分:1)

如果您已安装了xampp最新副本,请检查此链接以获取通过xampp发送电子邮件的完整文档。您必须先启用apache才能尝试访问以下链接

http://localhost/dashboard/docs/send-mail.html

答案 8 :(得分:0)

您必须为此定义SMTP服务器和端口。除了从现场主机发送邮件之外的所有内容。

This is a useful link regarding this

  

注意:端口应该未使用。请注意,有些   像Skype这样的应用程序使用默认端口,并通过阻止   发送邮件。

答案 9 :(得分:0)

花了一个多小时试图完成这项工作。对于所有发布不起作用的建议都遇到同样问题的人:你必须在你的XAMPP inrerface中重启Apache!只是重新启动XAMPP就行了!!

答案 10 :(得分:0)

此代码用于来自您的本地XAMPP和您的Gmail帐户的邮件。 这段代码非常简单,对我来说工作很容易。

在php.ini文件中进行以下更改

SMTP=smtp.gmail.com 
smtp_port=587 
sendmail_from = your@gmail.com 
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 
extension=php_openssl.dll 

在sendmail.ini文件中进行以下更改

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log 
auth_username=yourmail@gmail.com 
auth_password=your-gmail-password 
force_sender=yourmail@gmail.com  

请在您的PHP文件中写入belove代码以发送电子邮件

<?php 
    $to = "tomail@gmail.com";
    $subject = "Test Mail";
    $headers = "From: from_mail@gmail.com\r\n";
    $headers .= "Reply-To: replytomail@gmail.com\r\n";
    $headers .= "CC: theassassin.edu@gmail.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $message = '<html><body>';
    $message .= '<img src="//css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>Details</td></tr>";
    $message .= "<tr><td><strong>Email:</strong> </td><td>Details</td></tr>";
    $message .= "<tr><td><strong>Type of Change:</strong> </td><td>Details</td></tr>";
    $message .= "<tr><td><strong>Urgency:</strong> </td><td>Details</td></tr>";
    $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>Details</td></tr>";
    $addURLS = 'google.com';
    if (($addURLS) != '') {
        $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . $addURLS . "</td></tr>";
    }
    $curText = 'dummy text';           
    if (($curText) != '') {
        $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
    }
    $message .= "<tr><td><strong>NEW Content:</strong> </td><td>New Text</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";

    if(mail($to,$subject,$message,$headers))
    {
        echo "Mail Send Sucuceed";
    }
    else{
        echo "Mail Send Failed";    
    }
?>

答案 11 :(得分:0)

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

然后,我将MailHog用于本地smtp服务器,只需运行它即可。 本地主机: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 link

答案 12 :(得分:0)

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

auth_password =这是-不是-您的Gmail密码

由于新的Google安全问题,您应按照以下步骤为此目的输入应用程序密码:

  1. 转到“安全”标签中的https://accounts.google.com/
  2. 启用两步验证
  3. 返回安全标签并输入应用密码(在“选择应用”下拉菜单中,您可以选择“其他”)
相关问题