<?php
require_once "Mail.php";
$from = '<from.gmail.com>';
$to = '<to.yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
?>
但是,该程序在 $mail = $smtp->send($to, $headers, $body);
处失败:
validation failed: johndoe@gmail.com
我已确认电子邮件和密码正确无误。如果我提供无效密码,错误将更改为
incorrect password
我也尝试过在我的帐户上禁用两步验证,但这没有帮助。请告知为什么我可能会在凭据看起来正确的情况下收到此验证错误?
最佳答案
当您在您或收件人的电子邮件中使用无效字符作为电子邮件别名时,通常会收到“验证失败”。
例如:
my_email@gmail.com <first_name.last_name>
my_email@gmail.com <first_name@last_name>
无效字符是:
. (dots)
@ (at)
" (double quotes)
[ (bracket opened without closing)
] (bracket closed without opening)
( (parenthesis opened without closing)
) (parenthesis closed without opening)
关于php - : pear mail package 验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24996659/