簡體   English   中英

使用php腳本通過outlook發送郵件顯示空白屏幕

[英]Sending mail through outlook using php script shows blank screen

我們正在嘗試使用php代碼片段發送Outlook郵件,如下所示。 但是當我們使用localhost運行代碼時,它只顯示一個空白屏幕。 沒有郵件被發送或接收。 有人可以幫助我們嗎? 提前致謝。

Outlook.php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> MY MAIL </title>
</head>
<?php
$account="abc@outlook.com";
$password="****";
$to="xyz@outlook.com";
$from="abc@outlook.com";
$from_name="ABC";
$msg="Hello";
$subject="Hello World";

include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.live.com";
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->Username= $account;
$mail->Password= $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);
$mail->SMTPDebug = 1;
if(!$mail->send()){
 echo "Mailer Error: " . $mail->ErrorInfo;
}else{
 echo "E-Mail has been sent";
}
?>
<body>
</body>
</html>

試試這個php郵件代碼

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> MY MAIL </title>
</head>
<?php
$account="abc@outlook.com";
$password="****";
$to="xyz@outlook.com";
$from="abc@outlook.com";
$from_name="ABC";
$msg="Hello";
$subject="Hello World";

include("phpmailer/class.phpmailer.php");
 $mail = new PHPMailer(); // create a object to that class.
$mail->IsMail();
//$mail->IsSendmail();
$mail->Subject =  $subject;
$mail->From = $from;
$mail->FromName = $first_name." ".$surname;
$mail->AddAddress($to);
//$mail->AddBCC('seo@infiniteitsolutions.com.au');
$mail->Body = $mailBody;
$mail->IsHTML(true);
if(!$mail->send()){
 echo "Mailer Error: " . $mail->ErrorInfo;
}else{
 echo "E-Mail has been sent";
}
?>
<body>
</body>
</html>

您可以通過設置參數來調試郵件程序。

// enables SMTP debug information (for testing)
$mail->SMTPDebug  = 1;  // 1 = errors and messages
OR
$mail->SMTPDebug  = 2; // 2 = messages only

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

你可以在這里查看完整的例子

PHPMailer調試示例代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM