Php 如何配置XAMPP从本地主机发送邮件?
我正在尝试从本地主机发送邮件。 但是我无法从localhost发送邮件 那么,有谁能告诉我,如何重新配置我的xampp以从本地主机发送邮件,您必须在服务器上进行配置。您可以通过谷歌免费使用:Php 如何配置XAMPP从本地主机发送邮件?,php,xampp,Php,Xampp,我正在尝试从本地主机发送邮件。 但是我无法从localhost发送邮件 那么,有谁能告诉我,如何重新配置我的xampp以从本地主机发送邮件,您必须在服务器上进行配置。您可以通过谷歌免费使用: <?php $mail = new PHPMailer(true); // Send mail using Gmail if($send_using_gmail){ $mail->IsSMTP(); // telling the class to use SMTP $mail
<?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
服务器和端口。除了从现场主机发送邮件
注意:端口应未使用。请小心,一些
像Skype这样的应用程序使用默认端口,因此可以防止
发送邮件
您可以使用sendmail包从localhost发送邮件,sendmail包在XAMPP中是内置的。 因此,如果您使用的是XAMPP,那么您可以轻松地从localhost发送邮件 例如,您可以为gmail配置
C:\xampp\php\php.ini
和C:\xampp\sendmail\sendmail.ini
在C:\xampp\php\php.ini
中查找extension=php\u 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
现在你做到了!!使用mail函数创建php文件并从localhost发送邮件
注意:不要忘记在上面的代码中替换我的gmail id和我的gmail密码。
此外,如果从上面复制了设置,请不要忘记删除重复的关键点。例如,如果php.ini文件中存在另一个sendmail\u路径,请在下面的行中添加注释:sendmail\u path=“C:\xampp\mailtodisk\mailtodisk.exe”
还要记住使用XAMMP控制面板重新启动服务器,以便更改生效
对于gmail,请检查以允许从不太安全的应用程序访问
通过Gmail在Linux上发送电子邮件(带有sendmail软件包)
本地主机请检查
我花了一个多小时来做这件事。对于所有有同样问题的人来说,所有建议都不起作用:您必须在XAMPP Inerface中重新启动Apache!只是重新启动XAMPP是行不通的 在本地主机或本地服务器上发送电子邮件非常简单 注意:我使用的是安装了Xampp的64位Windows 7上的测试邮件服务器软件 只需下载测试邮件服务器工具,并根据其网站上给出的说明进行安装 现在只需更改
php.ini
文件下的两行
[邮件功能]
并删除之前的分号;smtp=localhost
sendmail\u path=“C:\xampp\mailtodisk\mailtodisk.exe”之前
SMTP端口
,您仍然没有收到电子邮件,则端口号必须相同
上述方法用于Xampp软件提供的默认设置。在Xampp v3.2.1中,出于测试目的,您可以在Xampp/mailoutput中查看Xampp发送的电子邮件。在我的Windows 8上,这不需要任何附加配置,是测试电子邮件的简单解决方案您可以在PC上测试发送邮件,而无需Internet 您应该使用这个简单的应用程序来测试发送邮件。您不需要配置任何东西 只需运行它并尝试测试发送邮件: 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上找到我,了解更多教程
加油 根据我个人的经验,我发现与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
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
auth_username=address@gmail.com
auth_password=YourPassword
<?php
mail($to, "subject", "body", "From: ".$from);
?>
通过放置,关闭邮件功能下的其他变量代码>在他们前面。e、 g;smtp_端口=25
步骤2(sendmail.ini文件)
在位于xampp\sendmail\semdmail.ini中的sendmail.ini中,更改为
以下:
extension=php_openssl.dll
[mail function]
sendmail_path =":\xampp7\sendmail\sendmail.exe -t"
mail.add_x_header=On
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
auth_username=address@gmail.com
auth_password=YourPassword
<?php
mail($to, "subject", "body", "From: ".$from);
?>
步骤3(代码)
创建一个php文件并使用以下命令:
extension=php_openssl.dll
[mail function]
sendmail_path =":\xampp7\sendmail\sendmail.exe -t"
mail.add_x_header=On
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
auth_username=address@gmail.com
auth_password=YourPassword
<?php
mail($to, "subject", "body", "From: ".$from);
?>
注意
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = your@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
extension=php_openssl.dll
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
- 需要重新启动apache才能重新加载php.ini
- 您需要在中激活Google不太安全的应用程序访问
- 使用管理员权限运行Xampp可能会有所帮助
此代码用于从本地主机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
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
下面是sendmail.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
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文件中编写以下代码以发送电子邮件
<?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";
}
?>
我尝试了许多方法从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!";
}
require_once“src/PHPMailer.php”;
需要一次“src/SMTP.php”;
需要一次“src/Exception.php”;
$mail=new PHPMailer\PHPMailer\PHPMailer();
//服务器设置
$mail->SMTPDebug=3;//启用详细调试输出
$mail->isSMTP();//使用SMTP发送
$mail->Host='localhost';//将SMTP服务器设置为通过发送
$mail->Port=1025;//要连接到的TCP端口
//$mail->Username='';//SMTP用户名
//$mail->Password='';//SMTP密码
//百万美元