Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP连接到Hotmail以发送电子邮件?_Php_Html_Phpmailer - Fatal编程技术网

PHP连接到Hotmail以发送电子邮件?

PHP连接到Hotmail以发送电子邮件?,php,html,phpmailer,Php,Html,Phpmailer,目前我正在尝试使用PHPmailer发送电子邮件。下面是代码 <?php require("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); // ---------- adjust these lines --------------------------- ------------ $mail->Username = "(username@hotmail.com)"; // you

目前我正在尝试使用PHPmailer发送电子邮件。下面是代码

<?php     
require("phpmailer/class.phpmailer.php");   
$mail = new PHPMailer();   // ---------- adjust these lines ---------------------------    ------------   
$mail->Username = "(username@hotmail.com)"; // your hotmail user name    
  $mail->Password = "password";
  $mail->AddAddress"(username@hotmail.com)"; // recipients email     
  $mail->FromName = "test"; // readable name     
  $mail->Subject = "Subject title";     
  $mail->Body    = "Here is the message you want to send to your friend.";     
  //-----------------------------------------------------------------------     
  $mail->Host = "smtp.live.com"; // GMail     
  $mail->Port = 25;     $mail->IsSMTP(); // use SMTP  
  $mail->SMTPAuth = true; // turn on SMTP authentication 
  $mail->From = $mail->Username;  
  if(!$mail->Send())     
      echo "Mailer Error: " . $mail->ErrorInfo;     
  else       
      echo "Message has been sent";     

  ?> 

我用PHPMailer尝试了smtp.live.com的SSL端口587,为什么不起作用

错误为“SMTP错误:无法连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机。”

我无法telnet smtp.live.com 25587。
smtp.gmail.com等。。我该怎么办(

端口587适合我

无需运行IsSMTP()。请将其注释掉,因为它将引发异常


如果它解决了您的问题,请不要忘记将其标记为答案:)端口587适合我

无需运行IsSMTP()。注释掉它,因为它会抛出异常

如果它解决了您的问题,请不要忘记将其标记为答案:)



塔哈的答案对我来说很有用。尝试注释$mail->IsSMTP();我还评论了这部分$mail->Port=587

Talha的答案对我来说很有用。尝试注释$mail->IsSMTP();我还评论了这部分$mail->Port=587

你说“我不能
telnet
smtp.live.com
”是什么意思?出现什么错误?无法打开与端口25上主机的连接;连接失败。@user127886,您的主机可能正在阻止这些端口。这很常见。嗨,布拉德,我还有别的办法吗?但奇怪的是,我的个人hotmail帐户可以发送到我公司的电子邮件,而我公司的电子邮件也可以发送到我的个人hotmail帐户,这意味着传入和传出的电子邮件都不会被阻止。我尝试了
telnet smtp.live.com 587
,效果很好。回复为
220 BLU0-SMTP166.phx.gbl Microsoft ESMTP邮件服务
。您所说的“我不能
telnet
smtp.live.com
”是什么意思?出现什么错误?无法打开与端口25上主机的连接;连接失败。@user127886,您的主机可能正在阻止这些端口。这很常见。嗨,布拉德,我还有别的办法吗?但奇怪的是,我的个人hotmail帐户可以发送到我公司的电子邮件,而我公司的电子邮件也可以发送到我的个人hotmail帐户,这意味着传入和传出的电子邮件都不会被阻止。我尝试了
telnet smtp.live.com 587
,效果很好。回复为
220 BLU0-SMTP166.phx.gbl Microsoft ESMTP邮件服务
。您的回答不真实您的回答不真实感谢您的回复感谢您的回复
<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                      // enables SMTP debug information (for testing)
                                            // 1 = errors and messages
                                            // 2 = messages only
$mail->SMTPAuth   = true;                   // enable SMTP authentication
$mail->SMTPSecure = "tls";                  // sets the prefix to the servier
$mail->Host       = "smtp.live.com";        // sets hotmil as the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the hotmail server
$mail->Username   = "useyourownemail@hotmail.com";      // hotmail username
$mail->Password   = "useyourownpassword";           // hotmail password
$mail->SetFrom('yourname@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject    = "PHPMailer Test Subject via smtp (hotmail), basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);

$address = "anemail@domain.com";
$mail->AddAddress($address, "John Doe");

$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!";
}

?>