我正在尝试从localhost发送邮件.但我无法从localhost发送邮件,所以任何人都可以告诉我如何重新配置我的xampp从localhost发送邮件
Vik*_*edi 354
您可以使用sendmail包从localhost发送邮件,在XAMPP中建立sendmail包.因此,如果您正在使用XAMPP,那么您可以轻松地从localhost发送邮件.
例如,您可以配置C:\xampp\php\php.ini和c:\xampp\sendmail\sendmail.ini为Gmail发送邮件.
在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"
Run Code Online (Sandbox Code Playgroud)
现在打开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
Run Code Online (Sandbox Code Playgroud)
现在你做到了!! 使用邮件功能创建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从localhost发送Linux(带有sendmail包)的电子邮件,请检查PHP + Ubuntu使用gmail form localhost发送电子邮件.
Pau*_*ter 34
在XAMPP v3.2.1中,出于测试目的,您可以看到XAMPP在XAMPP/mailoutput中发送的电子邮件.就我而言,在Windows 8上,这不需要任何其他配置,而且是测试电子邮件的简单解决方案
Vik*_*eta 25
在localhost或本地服务器上发送电子邮件非常简单
注意:我在安装了Xampp的Windows 7 64位上使用测试邮件服务器软件
只需下载测试邮件服务器工具,并按照其网站Test Mail Server Tool上的说明进行安装
现在您只需要在php.ini文件下更改两行
[mail function]并删除之前的半冒号;smtp = localhostsendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"您不需要更改任何其他内容,但如果您仍然没有收到电子邮件而不是检查SMTP port,则端口号必须相同.
上述方法适用于Xampp软件提供的默认设置.
Thi*_*gan 19
您必须在服务器上配置SMTP.您可以免费使用G Suite SMTP by Google:
<?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 :(";
}
?>
Run Code Online (Sandbox Code Playgroud)
了解更多关于PHPMailer 这里.
Pis*_*Sok 18
你应该使用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);
?>
Run Code Online (Sandbox Code Playgroud)
你会看到这个:
我希望你有一个美好的一天.你可以在Youtube上找到我的更多教程Piseth Sok
欢呼!
根据我的个人经验,我发现与 Vikas Dwivedi 答案非常相似的东西会很好用。
第 1 步(php.ini 文件)
在位于xampp\php\php.ini. 将设置更改为以下内容:
extension=php_openssl.dll
[mail function]
sendmail_path =":\xampp7\sendmail\sendmail.exe -t"
mail.add_x_header=On
Run Code Online (Sandbox Code Playgroud)
将其他变量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
Run Code Online (Sandbox Code Playgroud)
第 3 步(代码)
创建一个 php 文件并使用以下内容:
<?php
mail($to, "subject", "body", "From: ".$from);
?>
Run Code Online (Sandbox Code Playgroud)
注意
对于Windows 8上的人,如果你想这样做,我真的建议你阅读这个教程我发现:http://yogeshchaugule.com/blog/2013/configure-sendmail-wamp
它不是由我写的,而是在将我的头撞到混凝土墙上2.5小时之后,没有让它与最奇怪的错误一起工作:
我终于发现教程安装了https://www.stunnel.org/downloads.html和Stunnel的配置.它终于奏效了.
| 归档时间: |
|
| 查看次数: |
568121 次 |
| 最近记录: |