无法使用 PHPMailer 远程连接到我的电子邮件服务器
Cannot connect remotely to my email server using PHPMailer
我正在编写一个 PHP 脚本,使用 PHPMailer 自动发送电子邮件。
出于测试目的,我使用了一个带有应用程序密码的 Gmail 帐户,一切正常。
当我用我的专业电子邮件替换 Gmail 帐户配置时,PHP 连接脚本会持续加载一段时间并以此消息结束。
SMTPDebug 设置为 3。
2015-11-16 22:43:30 SERVER -> CLIENT: +OK Dovecot ready. 2015-11-16 22:43:30 CLIENT -> SERVER: EHLO localhost
这是什么意思?
这是我用来测试与电子邮件服务器的连接的 PHP 函数
<?php
require('../PHPMailer-master/PHPMailerAutoload.php');
function smtpMailer() {
$mail = new PHPMailer();
$mail->IsSMTP(); // active SMTP
$mail->SMTPDebug = 2;
$mail->Host = 'mail.mycompany.com';
$mail->Port = 587;
//$mail->Username = "myaccount@mycompany.com";
//$mail->Password = "mypassword";
$mail->SetFrom = "myaccount@mycompany.com";
$mail->FromName = 'foxy';
$mail->addAddress('sendTo@gmail.com', 'John Doe');
$mail->WordWrap = 50;
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the body in plain text ';
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
smtpMailer();
?>
错误
2015-11-17 01:44:14 SERVER -> CLIENT: 220 mycompany.com ESMTP Ready 2015-11-17 01:44:14
CLIENT -> SERVER: EHLO localhost 2015-11-17 01:44:14
SERVER -> CLIENT: 250-mycompany.com Hello localhost 250 HELP 2015-11-17 01:44:14
CLIENT -> SERVER: MAIL FROM: 2015-11-17 01:44:15
SERVER -> CLIENT: 250 root@localhost... Sender ok 2015-11-17 01:44:15
CLIENT -> SERVER: RCPT TO: 2015-11-17 01:44:16
SERVER -> CLIENT: 503 non-authenticated user. Please check mail before sending. 2015-11-17 01:44:16 SMTP ERROR: RCPT TO command failed: 503 non-authenticated user. Please check mail before sending. 2015-11-17 01:44:16
CLIENT -> SERVER: QUIT 2015-11-17 01:44:16
SERVER -> CLIENT: 221 goodbye. 2015-11-17 01:44:16 SMTP Error: The following recipients failed: sendTo@gmail.com: non-authenticated user. Please check mail before sending.
Mailer Error: SMTP Error: The following recipients failed: sendTo@gmail.com: non-authenticated user. Please check mail before sending.
谢谢。
这是我正在使用的代码
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->Username = "no-reply@mycompany.com";
$mail->Password = "password";
$mail->AddAddress($email);
$mail->FromName = "Any Text";
$mail->Subject = $sub;
$mail->IsHTML(true);
$mail->Body = $code;
$mail->Host = "192.168.20.47"; // Is IP example that I show here
$mail->Port = 25;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if ($mail->Send()) {
echo "Message send!";
}
else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
希望对您有所帮助。
我正在编写一个 PHP 脚本,使用 PHPMailer 自动发送电子邮件。 出于测试目的,我使用了一个带有应用程序密码的 Gmail 帐户,一切正常。 当我用我的专业电子邮件替换 Gmail 帐户配置时,PHP 连接脚本会持续加载一段时间并以此消息结束。 SMTPDebug 设置为 3。
2015-11-16 22:43:30 SERVER -> CLIENT: +OK Dovecot ready. 2015-11-16 22:43:30 CLIENT -> SERVER: EHLO localhost
这是什么意思?
这是我用来测试与电子邮件服务器的连接的 PHP 函数
<?php
require('../PHPMailer-master/PHPMailerAutoload.php');
function smtpMailer() {
$mail = new PHPMailer();
$mail->IsSMTP(); // active SMTP
$mail->SMTPDebug = 2;
$mail->Host = 'mail.mycompany.com';
$mail->Port = 587;
//$mail->Username = "myaccount@mycompany.com";
//$mail->Password = "mypassword";
$mail->SetFrom = "myaccount@mycompany.com";
$mail->FromName = 'foxy';
$mail->addAddress('sendTo@gmail.com', 'John Doe');
$mail->WordWrap = 50;
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the body in plain text ';
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
smtpMailer();
?>
错误
2015-11-17 01:44:14 SERVER -> CLIENT: 220 mycompany.com ESMTP Ready 2015-11-17 01:44:14
CLIENT -> SERVER: EHLO localhost 2015-11-17 01:44:14
SERVER -> CLIENT: 250-mycompany.com Hello localhost 250 HELP 2015-11-17 01:44:14
CLIENT -> SERVER: MAIL FROM: 2015-11-17 01:44:15
SERVER -> CLIENT: 250 root@localhost... Sender ok 2015-11-17 01:44:15
CLIENT -> SERVER: RCPT TO: 2015-11-17 01:44:16
SERVER -> CLIENT: 503 non-authenticated user. Please check mail before sending. 2015-11-17 01:44:16 SMTP ERROR: RCPT TO command failed: 503 non-authenticated user. Please check mail before sending. 2015-11-17 01:44:16
CLIENT -> SERVER: QUIT 2015-11-17 01:44:16
SERVER -> CLIENT: 221 goodbye. 2015-11-17 01:44:16 SMTP Error: The following recipients failed: sendTo@gmail.com: non-authenticated user. Please check mail before sending.
Mailer Error: SMTP Error: The following recipients failed: sendTo@gmail.com: non-authenticated user. Please check mail before sending.
谢谢。
这是我正在使用的代码
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->Username = "no-reply@mycompany.com";
$mail->Password = "password";
$mail->AddAddress($email);
$mail->FromName = "Any Text";
$mail->Subject = $sub;
$mail->IsHTML(true);
$mail->Body = $code;
$mail->Host = "192.168.20.47"; // Is IP example that I show here
$mail->Port = 25;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if ($mail->Send()) {
echo "Message send!";
}
else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
希望对您有所帮助。