从谷歌应用程序帐户发送PHP的电子邮件

时间:2015-10-30 16:07:19

标签: php codeigniter email gmail

我使用PHP发送电子邮件,但我们刚刚将所有内容迁移到Google应用。

我创建了一个新用户(support@xxxxxxxxxx.com),我不知道我要用它来发送电子邮件。

我正在使用Codeigniter代码:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com', //'ssl://smtp.googlemail.com'
    'smtp_port' => '587',
    'smtp_timeout' => '30',
    'smtp_user' => 'support@xxxxxxxxxx.com',
    'smtp_pass' => 'passExample',
    'mailtype' => 'html',
    'charset' => 'utf-8',
    'newline' => '\r\n',
    'wordwrap' => TRUE
);
$this->load->library('email', $config);

$this->email->from("support@xxxxxxxxxx.com", "Support");
$this->email->to($to);
$this->email->subject($subject);

$this->email->message($message);
if($this->email->send())
{
    return true;
}
else
{
    $error=$CI->email->print_debugger();
    return $error;
}

任何帮助??

我尝试关注此链接: https://support.google.com/a/answer/176600?hl=es 还有这个 https://support.google.com/a/answer/2956491

这就是我在谷歌应用程序的gmail管理面板上所拥有的: Google Apps admin Panel

密码正确,因为我可以登录Gmail,这些是错误:

  

使用端口:25和主机:aspmx.l.google.com

sendEmail=220 mx.google.com ESMTP 142si1984800wmg.122 - gsmtp 
hello: 250-mx.google.com at your service, [2a02:be8:1:700:4525:cbbd:7e41:9fed]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
error sending AUTH LOGIN command. Error: 503 5.5.1 bad sequence of commands 142si1984800wmg.122 - gsmtp 
from: 250 2.1.0 OK 142si1984800wmg.122 - gsmtp
to: 250 2.1.5 OK 142si1984800wmg.122 - gsmtp
data: 354  Go ahead 142si1984800wmg.122 - gsmtp
  

带端口的SSL:465和主机:smtp.gmail.com

     

TLS与端口:587和主机:smtp.gmail.com

hello: F
SMTP The following errors have been found:
error sending AUTH LOGIN command. Error: 
from: 
SMTP The following errors have been found:
to: 
SMTP The following errors have been found:
data: 
SMTP The following errors have been found:
You can not send mail using SMTP PHP. Your server may be configured to use this method of shipment.

2 个答案:

答案 0 :(得分:1)

我解决了!

问题在于使用Codeignter 2.X它不起作用。我下载了codeigniter 3,它适用于我这个配置:

$config = Array(
        'useragent' => 'ermes',
        'protocol' => 'mail',
        'smtp_host' => 'smtp.gmail.com',
        'smtp_port' => '465',
        'smtp_user' => 'support@xxxxxxxxxxxx.com',
        'smtp_pass' => 'xxxxxxxxxxxx',
        'smtp_crypto' => 'ssl',
        'mailtype' => 'html',
        'charset' => 'utf-8',
        'newline' => '\r\n',
        'wordwrap' => TRUE
    );

我需要将协议从smtp更改为mail并添加smtp_crypto(此函数不在Codeigniter 2.X中)

此外,我没有在我的gmail配置中进行更改(在谷歌应用程序中)。

答案 1 :(得分:0)

使用谷歌应用程序发送电子邮件需要几个步骤才能完成谷歌实际开始发送您要求的电子邮件...

问题是什么:

您需要激活从谷歌发送来自不安全来源的电子邮件。

怎么做:

首次执行代码时,gmail会向您发送电子邮件至support@xxxxxxxxxx.com,您需要点击激活按钮。之后谷歌将转发所有电子邮件

为什么会发生这种情况

使用php直接发送电子邮件通常被视为垃圾邮件。因此需要进行一次安全检查。

希望您的代码开始正常运行,您还需要检查您的托管是否具有无限的电子邮件转发功能。

祝你好运......