php 来自本地主机的 PHPmailer?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19777402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:00:34  来源:igfitidea点击:

PHPmailer from localhost?

phpsmtpphpmailer

提问by bagofmilk

I'm very new to PHP. I downloaded a phpmailer script (with files) from here -> phpmailer

我对 PHP 很陌生。我从这里下载了一个 phpmailer 脚本(带文件)-> phpmailer

I'm using XAMPP and I located the files in:

我正在使用 XAMPP 并将文件定位在:

\htdocs\QMS\phpmailer

\htdocs\QMS\phpmailer

My php script resides in: \htdocs\QMS\

我的 php 脚本位于:\htdocs\QMS\

I get the message that the mail was sent, but I do not see anything in my inbox, trash, or spam. I tried other email addresses and still nothing.

我收到邮件已发送的消息,但我在收件箱、垃圾箱或垃圾邮件中没有看到任何内容。我尝试了其他电子邮件地址,但仍然没有。

Here's the code: (*email addresses and names have been masked with "xxx")

这是代码:(*电子邮件地址和名称已被“xxx”屏蔽)

<?php
require_once('phpmailer/class.phpmailer.php');

$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->AddReplyTo("[email protected]","xxx xxx");
$mail->SetFrom('[email protected]","xxx xxx');

$mail->AddReplyTo('[email protected]","xxx xxx');

$body = "This is a test... It works!";
$address = "[email protected]";
$mail->AddAddress($address, "xxx xxx");

$mail->Subject    = "A subject line here";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

回答by hbCyber

I know I'm late to the party, but if someone stumbles here and is looking for a quick solution for trying e-mails on your localhost, you can use this nice freeware to run a fake SMTP server on your computer which will let you 'see' the e-mails a real SMTP server would have received and sent (it doesn't actually send anything).

我知道我迟到了,但是如果有人在这里绊倒并正在寻找在本地主机上尝试电子邮件的快速解决方案,您可以使用这个不错的免费软件在您的计算机上运行一个假的 SMTP 服务器,这将让您“查看”真实 SMTP 服务器接收和发送的电子邮件(它实际上不发送任何内容)。

http://nilhcem.github.io/FakeSMTP/

http://nilhcem.github.io/FakeSMTP/

Super useful during development and testing.

在开发和测试过程中超级有用。

回答by mti2935

The way you have setup your PHPMailer, it would require an SMTP server running on your localhost to send the messages. If you don't have an SMTP server running on your localhost, then you can use an external SMTP server to relay the messages through. To know more about PHPMailer, Please refer below for a working example of how to do this with PHPMailer.

按照您设置 PHPMailer 的方式,它需要在您的本地主机上运行的 SMTP 服务器来发送消息。如果本地主机上没有运行 SMTP 服务器,则可以使用外部 SMTP 服务器来中继消息。要了解有关 PHPMailer 的更多信息,请参阅以下有关如何使用 PHPMailer 执行此操作的工作示例。

Having trouble with PHPMailer

使用 PHPMailer 时遇到问题

.

.