使用核心php mail()通过gmail SMTP发送

时间:2022-11-15 12:22:26

Is it possible to send mail in core php via gmail smtp without using any external class?

是否可以通过gmail smtp在核心php中发送邮件而无需使用任何外部类?

5 个解决方案

#1


7  

I don't think it is possible because you need to perform an authentification. Also, you need to connect via an SSL socket, I don't know if the stock mail() function support this.

我不认为这是可能的,因为你需要进行身份验证。此外,您需要通过SSL套接字连接,我不知道stock mail()函数是否支持此功能。

If you are willing to use the Pear Mail package, you might want to take a look at this:

如果您愿意使用Pear Mail软件包,您可能需要查看以下内容:

Send email using the GMail SMTP server from a PHP page

从PHP页面使用GMail SMTP服务器发送电子邮件

#2


17  

There's a lot of miscommunication about this. It is 100% possible to send emails using gmail via PHP's simple "mail()" command. And it is 100% easy.

对此有很多误解。通过PHP的简单“mail()”命令使用gmail发送电子邮件是100%可能的。这很简单。

Install SSMTP:

sudo apt-get install ssmtp

Edit its settings file:

编辑其设置文件:

sudo nano /etc/ssmtp/ssmtp.conf

Inside, make it similar to this, but with your own credentials:

在里面,使它类似于此,但使用您自己的凭据:

mailhub=smtp.gmail.com:587
AuthUser=youremail@gmail.com
AuthPass=password
UseSTARTTLS=YES

# You can only do this if you've verified your domain with Gmail.
# If you haven't, delete, or add a # before this
hostname=yourwebsite.com

FromLineOverride=YES

Lastly, open your php.ini, and search for sendmail_path and use this value:

最后,打开你的php.ini,搜索sendmail_path并使用这个值:

sendmail_path = /usr/sbin/ssmtp -t

That's it! Test it out in your PHP, with the simple 1-line mail function:

而已!使用简单的1行邮件功能在PHP中测试它:

mail('to@address.com', 'Subject', 'Message', 'From: Your name <youremail@gmail.com>');

Update on Gmail Security

Gmail now blocks this by default. You can still do this by visiting: http://www.google.com/settings/security/lesssecureapps

Gmail现在默认阻止此操作。您仍然可以访问:http://www.google.com/settings/security/lesssecureapps

Turn this feature ON.

打开此功能。

#3


4  

It is possible, although you have to modify php.ini settings, see the PHP manual. You can modify php.ini settings at runtime with ini_set

虽然你必须修改php.ini设置,但有可能参见PHP手册。您可以使用ini_set在运行时修改php.ini设置

#4


1  

If you have access to edit the php.ini then you can do something like this:

如果您有权编辑php.ini,那么您可以执行以下操作:

[mail function]
SMTP = ssl://smtp.gmail.com
smtp_port = 465
username = info@Mmydomainname.com
password = myemailpassword
sendmail_from = info@mydomainname.com

Alternatively you can do:

或者你可以这样做:

<?php
ini_set( 'smtp_port', 465 );
//etc

#5


-1  

you can do this by PHPmailer Library it already having gmail.php file .

你可以通过PHPmailer Library做到这一点,它已经有了gmail.php文件。

just open and place your detail in that file , you can also use the similar code in your file .

只需打开并将您的详细信息放在该文件中,您也可以使用文件中的类似代码。

You must make setting in your gmail account setting to allow smtp mailing

您必须在您的Gmail帐户设置中进行设置以允许smtp邮件

#1


7  

I don't think it is possible because you need to perform an authentification. Also, you need to connect via an SSL socket, I don't know if the stock mail() function support this.

我不认为这是可能的,因为你需要进行身份验证。此外,您需要通过SSL套接字连接,我不知道stock mail()函数是否支持此功能。

If you are willing to use the Pear Mail package, you might want to take a look at this:

如果您愿意使用Pear Mail软件包,您可能需要查看以下内容:

Send email using the GMail SMTP server from a PHP page

从PHP页面使用GMail SMTP服务器发送电子邮件

#2


17  

There's a lot of miscommunication about this. It is 100% possible to send emails using gmail via PHP's simple "mail()" command. And it is 100% easy.

对此有很多误解。通过PHP的简单“mail()”命令使用gmail发送电子邮件是100%可能的。这很简单。

Install SSMTP:

sudo apt-get install ssmtp

Edit its settings file:

编辑其设置文件:

sudo nano /etc/ssmtp/ssmtp.conf

Inside, make it similar to this, but with your own credentials:

在里面,使它类似于此,但使用您自己的凭据:

mailhub=smtp.gmail.com:587
AuthUser=youremail@gmail.com
AuthPass=password
UseSTARTTLS=YES

# You can only do this if you've verified your domain with Gmail.
# If you haven't, delete, or add a # before this
hostname=yourwebsite.com

FromLineOverride=YES

Lastly, open your php.ini, and search for sendmail_path and use this value:

最后,打开你的php.ini,搜索sendmail_path并使用这个值:

sendmail_path = /usr/sbin/ssmtp -t

That's it! Test it out in your PHP, with the simple 1-line mail function:

而已!使用简单的1行邮件功能在PHP中测试它:

mail('to@address.com', 'Subject', 'Message', 'From: Your name <youremail@gmail.com>');

Update on Gmail Security

Gmail now blocks this by default. You can still do this by visiting: http://www.google.com/settings/security/lesssecureapps

Gmail现在默认阻止此操作。您仍然可以访问:http://www.google.com/settings/security/lesssecureapps

Turn this feature ON.

打开此功能。

#3


4  

It is possible, although you have to modify php.ini settings, see the PHP manual. You can modify php.ini settings at runtime with ini_set

虽然你必须修改php.ini设置,但有可能参见PHP手册。您可以使用ini_set在运行时修改php.ini设置

#4


1  

If you have access to edit the php.ini then you can do something like this:

如果您有权编辑php.ini,那么您可以执行以下操作:

[mail function]
SMTP = ssl://smtp.gmail.com
smtp_port = 465
username = info@Mmydomainname.com
password = myemailpassword
sendmail_from = info@mydomainname.com

Alternatively you can do:

或者你可以这样做:

<?php
ini_set( 'smtp_port', 465 );
//etc

#5


-1  

you can do this by PHPmailer Library it already having gmail.php file .

你可以通过PHPmailer Library做到这一点,它已经有了gmail.php文件。

just open and place your detail in that file , you can also use the similar code in your file .

只需打开并将您的详细信息放在该文件中,您也可以使用文件中的类似代码。

You must make setting in your gmail account setting to allow smtp mailing

您必须在您的Gmail帐户设置中进行设置以允许smtp邮件