以下是第一次调用正在运行的示例代码,但第二次类似的事情未能发送邮件: 您可以看到两个函数都是对称的。
<?php
include_once "Swift-5.1.0/lib/swift_required.php";
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername('Username');//smtp Access
$transport->setPassword('Password');//smtp Access
$swift = Swift_Mailer::newInstance($transport);
function call1(){
//...subject/from/to/text/html
global $swift;
$message=NULL;
$message = new Swift_Message($subject);
$headers = $message->getHeaders();
$message->setFrom($from);
$message->setTo($to);
$htmlPart = new Swift_MimePart($html, 'text/html');
$message->attach($htmlPart);
$textPart = new Swift_MimePart($text, 'text/plain');
$message->attach($textPart);
if ($recipients = $swift->send($message, $failures))
{
$mailsent = true;
return true;
} else {
$mailsent = false;
return false;
}
}
function call2(){
//...subject/from/to/text/html
global $swift;
$message=NULL;
$message = new Swift_Message($subject);
$headers = $message->getHeaders();
$message->setFrom($from);
$message->setTo($to);
$htmlPart = new Swift_MimePart($html, 'text/html');
$message->attach($htmlPart);
$textPart = new Swift_MimePart($text, 'text/plain');
$message->attach($textPart);
if ($recipients = $swift->send($message, $failures))
{
$mailsent = true;
return true;
} else {
$mailsent = false;
return false;
}
}
call1();//Working
call2();//Not Working
call1();//Not Working
call2();//Not Working
?>
答案 0 :(得分:0)
确保您的邮件应用设置不会过于频繁地检查新电子邮件。如果您的邮件应用每10分钟检查一次以上的新邮件,则可能会阻止该应用对您帐户的访问权限。