我发送一封带有php的电子邮件时出错,因为我有一个smtp服务器名称调用smtp.office365.com,我该怎么办?
<?php
require "PHPmailer/src/PHPMailer.php";//Am I correctly include thelibraries?
require "PHPmailer/src/smtp.php";
$mail = new PHPMailer(true); >I get an error
$mail->isSMTP();
$mail->Host='smtp.office365.com';
$mail->Port=25;
$mail->SMTPAuth= true;
$mail->Username='username';//What username have I had to type?
$mail->Password='password';//The password is above office365 email?
$mail->SetFrom('sender_email', 'FromEmail');
$mail->addAddress('destination', 'ToEmail');
$mail->IsHTML(true);
$mail->Subject='Here is the subject';
$mail->Body= 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
?>
我收到错误,因为当我尝试在服务器Linux上执行它时它不会发送电子邮件而它给了我一个'HTTP ERROR 500'
答案 0 :(得分:0)
$mail->Host=smtp.office365.com
$mail->Port=587
$mail->Username=XXXXXXX
$mail->Password=XXXXXXX
$mail->Encryption=tls
答案 1 :(得分:0)
require "PHPmailer/src/PHPMailer.php";
require "PHPmailer/src/smtp.php";
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for 365
$mail->Host = 'smtp.office365.com';
$mail->Port = 25;
$mail->Username = 'username';
$mail->Password = "password";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress('myemail@gmail.com');