在 php 和本地邮件服务器 hMailServer 中使用 SwiftMailer 包。php代码:
<?php
require 'vendor/autoload.php';
$message=Swift_Message::newInstance();
$message->setFrom('webmaster@mail.com');
$message->setTo(array('testmail@mail.com'=>'Ilqar Rasulov'));
$message->setSubject('Delicious New Recipe');
//$message->setBody(<<<_TEXT_
//Dear James,
//You should try this: puree 1 pound of chicken with two pounds
//of asparagus in the blender, then drop small balls of the mixture
//into a deep fryer. Yummy!
//Love,
//Julia
//_TEXT_
//);
$message->addPart(<<<_TEXT_
<p>Dear James,</p>
<p>You should try this:</p>
<ul>
<li>puree 1 pound of chicken with two pounds
of asparagus in the blender</li>
<li>then drop small balls of the mixture into a deep fryer.</li>
</ul>
<p><em>Yummy!</em></p>
<p>Love,</p>
<p>Julia</p>
_TEXT_
, "text/html");
try{
$transport= Swift_SmtpTransport::newInstance('localhost',25);
$mailer= Swift_Mailer::newInstance($transport);
$mailer->send($message);
} catch (Exception $ex){
print $ex->getMessage();
}
我已经配置了我的 hMailServer 并分配了密码(管理员和帐户密码)。所以问题是为什么 swiftmailer 只需要主机名和密码来完成它的工作,并且不需要身份验证?因为我不记得我在任何配置文件中存储了用户名和密码。