简体   繁体   English

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

[英]Send email in PHP from a google apps account

I was sending emails with PHP but we have just migrated all to google apps.我用 PHP 发送电子邮件,但我们刚刚全部迁移到谷歌应用程序。

I have created a new user (support@xxxxxxxxxx.com) and I don't known what I have to do to send emails with it.我创建了一个新用户 (support@xxxxxxxxxx.com),但我不知道我必须做什么才能用它发送电子邮件。

I am using Codeigniter with this code:我正在使用带有以下代码的 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;
}

Any help??有什么帮助吗??


I try to follow this link: https://support.google.com/a/answer/176600?hl=es and this https://support.google.com/a/answer/2956491我试着点击这个链接: https : //support.google.com/a/answer/176600?hl=es和这个https://support.google.com/a/answer/2956491

And this is what I have on gmail admin panel of google apps:这就是我在 google 应用程序的 gmail 管理面板上的内容: Google Apps 管理面板

The password is correct because I can log in into Gmail and these are the errors:密码正确,因为我可以登录 Gmail 并且这些是错误:

with port: 25 and host:aspmx.l.google.com使用端口: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 with port: 465 and host:smtp.gmail.com SSL 端口:465 和主机:smtp.gmail.com

TLS with port: 587 and host: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.

I solve it!我解决!

The problem is that with Codeignter 2.X it doesn't work.问题是使用 Codeignter 2.X 它不起作用。 I download codeigniter 3 and it works for me with this configuration:我下载了 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
    );

I need to change the protocol from smtp to mail and add smtp_crypto (this function is not in Codeigniter 2.X)我需要将协议从 smtp 更改为邮件并添加 smtp_crypto (此功能不在 Codeigniter 2.X 中)

Also I did not make changes in my gmail configration (in google apps).此外,我没有更改我的 gmail 配置(在谷歌应用程序中)。

Sending email using google app requires few steps to complete before google actually start sending the emails you ask for...在谷歌实际开始发送您要求的电子邮件之前,使用谷歌应用程序发送电子邮件需要完成几个步骤...

what's the problem:有什么问题:

You need to activate sending emails from unsecured sources from google.您需要激活从 google 发送来自不安全来源的电子邮件。

How to do it:怎么做:

gmail will send you an email to support@xxxxxxxxxx.com when first time you execute the code, where your required to click on activate button.当您第一次执行代码时,gmail 会向您发送一封电子邮件至 support@xxxxxxxxxx.com,您需要点击激活按钮。 After that all the emails google will forward之后谷歌将转发的所有电子邮件

Why this happens为什么会发生这种情况

Sending email directly using php is generally considered as spam.直接使用 php 发送电子邮件通常被认为是垃圾邮件。 so security check for 1 time is required.所以需要进行1次安全检查。

Hope you get your code started working, you also need to check that your hosting has unlimited email forwarding facility.希望您的代码开始工作,您还需要检查您的主机是否具有无限制的电子邮件转发功能。

best luck...好运...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 到现在 Google 停止了不太安全的应用程序,如何使用 PHPMailer 从 GMail 帐户发送电子邮件? - As on now Less Secure Apps stopped by Google, how to use PHPMailer to send email from GMail account? 无法使用带有PHPMailer的Google Apps帐户发送电子邮件 - Can't send an email using a google apps account with PHPMailer 使用Google Apps Engine和PHP将邮件发送到格式化的电子邮件地址 - Send a mail to formatted email address using Google Apps Engine and PHP 使用Google Apps Engine和PHP将邮件发送到格式化的电子邮件地址 - Send a mail to formatted email address using Google Apps Engine and PHP PHP将电子邮件发送到错误的帐户 - PHP send email to wrong account PHP / HTML表单数据将作为电子邮件从我的GMAIL帐户发送 - PHP/HTML form data to send as an email from my GMAIL account 可以从邮件客户端/ UNIX帐户发送电子邮件,但不能从PHP发送电子邮件 - Can send email from mail client/ unix account but not PHP 如何使用PHP从IMAP帐户发送电子邮件? - How do you send email from IMAP account with PHP? Google企业应用套件:未接收到PHP邮件发送的来自同一域的电子邮件 - Google Apps: Not receiving email from same domain sent by PHP mail() 从本地主机发送电子邮件到外部电子邮件帐户 - send email from localhost to external email account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM