【问题标题】:Validation failed for: pear mail package验证失败:梨邮件包
【发布时间】:2014-09-19 17:22:49
【问题描述】:
<?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-&gt;send($to, $headers, $body); 处失败:

验证失败:johndoe@gmail.com

我已确认电子邮件和密码正确无误。如果我提供的密码无效,错误将变为

密码错误

我还尝试在我的帐户上禁用两步验证,但这没有帮助。请告知为什么当凭据看起来正确时我可能会收到此验证错误?

【问题讨论】:

  • 你有什么问题?
  • 我看到的只是代码。你确定你的依赖设置正确吗?
  • 我正在使用这个我收到错误“验证失败:example@gmail.com”
  • 我设置正确。使用我自己的邮件地址,但它不起作用
  • 只是为了检查一下,您的帐户是否设置了双重身份验证?不确定ssl://smtp.gmail.com 是否强制执行此操作,但认为值得评论以预先排除。

标签: php email pear


【解决方案1】:

当我尝试设置mailFrom 有空格且没有电子邮件时出现此错误:

$this->mailFrom = "Lorem ipsum";'

只需用电子邮件地址更改即可:

$this->mailFrom = "Lorem ipsum <no-reply@test.com>";

【讨论】:

    【解决方案2】:

    我收到了同样的错误。

    在尝试了对我有用的领域之后:

    代替

    $from = "Sender <sender@example.com>";
    

    试试

    $from = "sender@example.com";
    

    所以您在发件人字段中只有发件人电子邮件地址。没有其他的。没有括号。

    我承认,这不是一个非常优雅的解决方案,但仍然是一个解决方案。

    【讨论】:

      【解决方案3】:

      当您在您或收件人的电子邮件中使用无效字符作为电子邮件别名时,通常会收到“验证失败”。

      例如:

      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)
      

      【讨论】:

        【解决方案4】:

        即使是迟到的答案,我也会将其发布给其他人。 “验证失败:”是针对接收者地址而不是您的凭据。 问题是收件人地址的格式错误,Gmail 不接受。

        //instead of 
        $to = '<to.yahoo.com>';
        //use
        $to = 'Recipient Name <myname@example.com>'
        //or simple 
        $to = 'myname@example.com';
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-12-28
          • 2015-06-15
          • 1970-01-01
          • 1970-01-01
          • 2012-04-17
          • 2015-11-09
          • 2014-01-30
          • 2013-11-01
          相关资源
          最近更新 更多