我试图从本地主机发送邮件。 但是我无法从本地主机发送邮件 所以有人能告诉我如何重新配置我的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的信息。
您可以测试发送邮件在您的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和您的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文件中的Change
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";
}
?>
您必须为此定义一个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可能会有所帮助。
推荐文章
- 自动删除Laravel (Eloquent ORM)中的相关行
- 在取消设置元素后重新设置数组键
- 如何修剪空白的数组值在php
- PHP中的双not(!!)操作符
- 在PHP5中创建单例设计模式
- 阻止人们入侵基于php的Flash游戏高分表的最佳方法是什么
- PHP子字符串提取。获取第一个'/'之前的字符串或整个字符串
- __construct函数的作用是什么?
- PHP中的异步shell执行器
- Laravel 5 -如何访问在视图存储上传的图像?
- XAMPP -端口80被PID 4的“无法打开进程”使用!12
- 为什么在PHP中使用sprintf函数?
- “质量分配”在Laravel中是什么意思?
- 在逗号上爆炸字符串,并修剪每个值的潜在空格
- PHP与MySQL 8.0+错误:服务器请求身份验证方法未知的客户端