PHPMailer未发送到Outlook.com
背景:PHPMailer未发送到Outlook.com,php,security,email,outlook,Php,Security,Email,Outlook,背景: require 'Classes/mail/PHPMailerAutoload.php'; $mail = new PHPMailer; $recipient = $_POST['email_address']; $recipient = preg_replace( '/\s+/', '', $recipient ); $recipient = trim( $recipient, ';' ); $recipient_array = explode( ';', $recipient
require 'Classes/mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$recipient = $_POST['email_address'];
$recipient = preg_replace( '/\s+/', '', $recipient );
$recipient = trim( $recipient, ';' );
$recipient_array = explode( ';', $recipient );
$subject = $_POST['email_subject'];
$body = nl2br( $_POST['email_message'] );
$footer = '<br />
<table id="email_footer">
<tr>
<td>
EMAIL SIGNATURE
</td>
</tr>
<tr>
<td>
<hr />
FOOTER IMAGE
<hr />
</td>
</tr>
<tr>
<td style="font-size:15px">
ADDRESS
</td>
</tr>
</table>';
$attachment = 'pdf/' . $_POST['attachment'];
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'webmaster@example.com'; // SMTP username
$mail->Password = 'password123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = "25"; // TCP port to connect to
$mail->SMTPOptions = array (
'ssl' => array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom( 'webmaster@example.com', 'Business Name' );
$mail->addReplyTo( 'webmaster@example.com', 'Business Name' );
for ( $i = 0; $i < count( $recipient_array ); $i++ )
{
$mail->addAddress( $recipient_array[$i] );
}
$mail->addAddress( 'example@zoho.com' ); // Forwards to local email for records (cannot send email to own server [workaround])
$mail->Subject = $subject; // Subject
$mail->Body = $body . '<br />' . $footer; // Body of email
$mail->AddAttachment( $attachment, 'purchase-order.pdf' ); // Attach a file
$mail->isHTML( true ); // Set email format to HTML
if( !$mail->send() )
{
echo 'Message could not be sent.<br />';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
我一直在使用我的网站发送电子邮件,但最近,某些人无法接收我的电子邮件
我测试了这个问题,似乎电子邮件无法发送到Outlook.com上的电子邮件
另一方面,这些电子邮件可以发送到我测试过的所有其他电子邮件服务,包括Gmail和Zoho
我已经尝试过使用$mail->SMTPAuth=true
()和我从其他地方找到的作为建议的$mail->SMTPOptions
()变通方法
$mail->send()
似乎返回true
,我没有收到来自$mail->ErrorInfo
的任何错误
无论如何,我发送的电子邮件不会发送到Outlook.com的电子邮件地址
是否需要添加某种安全功能以允许发送到Outlook电子邮件地址?
请让我知道,如果有任何其他信息,我可以提供。任何帮助都将不胜感激
PHPMailer代码:
require 'Classes/mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$recipient = $_POST['email_address'];
$recipient = preg_replace( '/\s+/', '', $recipient );
$recipient = trim( $recipient, ';' );
$recipient_array = explode( ';', $recipient );
$subject = $_POST['email_subject'];
$body = nl2br( $_POST['email_message'] );
$footer = '<br />
<table id="email_footer">
<tr>
<td>
EMAIL SIGNATURE
</td>
</tr>
<tr>
<td>
<hr />
FOOTER IMAGE
<hr />
</td>
</tr>
<tr>
<td style="font-size:15px">
ADDRESS
</td>
</tr>
</table>';
$attachment = 'pdf/' . $_POST['attachment'];
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'webmaster@example.com'; // SMTP username
$mail->Password = 'password123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = "25"; // TCP port to connect to
$mail->SMTPOptions = array (
'ssl' => array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom( 'webmaster@example.com', 'Business Name' );
$mail->addReplyTo( 'webmaster@example.com', 'Business Name' );
for ( $i = 0; $i < count( $recipient_array ); $i++ )
{
$mail->addAddress( $recipient_array[$i] );
}
$mail->addAddress( 'example@zoho.com' ); // Forwards to local email for records (cannot send email to own server [workaround])
$mail->Subject = $subject; // Subject
$mail->Body = $body . '<br />' . $footer; // Body of email
$mail->AddAttachment( $attachment, 'purchase-order.pdf' ); // Attach a file
$mail->isHTML( true ); // Set email format to HTML
if( !$mail->send() )
{
echo 'Message could not be sent.<br />';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
require'Classes/mail/phpmailerautoad.php';
$mail=新的PHPMailer;
$recipient=$\u POST['email\u address'];
$recipient=preg_replace(“/\s+/”,“$recipient”);
$recipient=trim($recipient,“;”);
$recipient_array=分解(“;”,$recipient);
$subject=$\u POST['email\u subject'];
$body=nl2br($_POST['email_message']);
$footer='
电子邮件签名
页脚图像
地址
';
$attachment='pdf/'$_职位[‘附件’];
$mail->isSMTP();//将邮件程序设置为使用SMTP
$mail->Host='localhost';//指定主SMTP服务器和备份SMTP服务器
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username=webmaster@example.com'; // SMTP用户名
$mail->Password='password123';//SMTP密码
$mail->SMTPSecure='tls';//启用TLS加密,也接受'ssl'
$mail->Port=“25”;//要连接到的TCP端口
$mail->SMTPOptions=array(
“ssl”=>数组(
“验证对等方”=>false,
'verify_peer_name'=>false,
“允许自签名”=>true
)
);
$mail->setFrom('webmaster@example.com","企业名称";;
$mail->addReplyTo('webmaster@example.com","企业名称";;
对于($i=0;$iaddAddress($recipient_数组[$i]);
}
$mail->addAddress('example@zoho.com' ); // 转发到本地电子邮件以获取记录(无法将电子邮件发送到自己的服务器[解决方法])
$mail->Subject=$Subject;//主题
$mail->Body=$Body'
$页脚;//电子邮件正文
$mail->AddAttachment($attachment,'purchase order.pdf');//附上文件
$mail->isHTML(正确);//将电子邮件格式设置为HTML
如果(!$mail->send())
{
echo“无法发送消息。
”;
回显“邮件错误:”。$mail->ErrorInfo;
}
谢谢您抽出时间。我想您的代码工作正常。 我曾经尝试向朋友发送邀请,但在OUTLOOK中遇到了类似的问题 这里有两件事要考虑。
不要一次发送给太多的收件人,这看起来像是垃圾邮件,对吗?最好一个接一个,如果可以,请使用稍微不同的电子邮件主题。
不要发送得太快,使用睡眠方法几秒钟后再发送一封电子邮件。否则,一些电子邮件提供商会认为您是DoS攻击者
它们进行通信并将消息返回给您。
在您的情况下,您不会从$mail->ErrorInfo收到任何错误,
案例1。如果您在之前成功向outlook发送电子邮件:
我想,您的请求可能无法到达电子邮件服务器。(我猜你被挡了)。请与OUTLOOK联系。
案例2。如果您以前从未成功向outlook发送电子邮件: 请检查电子邮件配置或防火墙和网络设置等
希望这将给您提供简短的指导。您好,欢迎来到代码审阅!不幸的是,这是一个人们为改进而检查已完成和完整代码的站点,而不是修复已损坏的代码。您可能可以找到有关堆栈溢出的解决方案。我的最佳猜测是,问题与您的实际代码无关,而是Outlook.com邮件网关正在阻止/过滤电子邮件。您使用的是DKIM还是SPF?我的意思是,据我所知,您的代码有问题,因为您已经声明无法向Outlook帐户发送邮件。在我看来,我想修复你的代码,这就是为什么