2020 年使用 PHP 7.2 设置 SMTP 邮件 - PHP 2020 年邮件
Setting up SMTP mailing with PHP 7.2 in 2020 - PHP Mailing in 2020
我想知道如何在 2020 年 php 7.2 中设置自动 SMTP 邮件系统。
我知道 mail()
功能,但它是在初始设置之后出现的。
我在 Whosebug 上看到了关于它的其他问题,但我发布这个问题是因为我只发现 outdated 问题来自 2011[=58] =] 或 2012 和 PHP 从那时起在安全方面和其他方面发生了很大的变化 。
这是我尝试过的:
From what I found I should be changing ini_set()
in php.ini
file but there are none of ini_set()
functions there. What I did is I changed smtp
to smtp=my-mail-server-of-choice-here
and smtp_port
to smtp_port=587
like I was told to.
Also, I should be updating sendmail.ini
in sendmail
folder but (guess what) sendmail folder
doesn't exist -> that also means sendmail.exe
and sendmail.ini
also don't exist
我也遇到这个错误mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first
这是文件:
$to = 'my-users-mail@some-random.mail';
$subject = "HTML email";
$message = "Hi Bob!";
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html;charset=UTF-8"."\r\n";
$headers .= 'From: my-mail@gmail.com'."\r\n";
mail($to,$subject,$message,$headers);
哪个(根据我读到的)应该可以从 ini_set()
修复 php.ini
文件中的任何地方 - 我猜 bc 只有提供过时的解决方案
什么是 现代 标准,php 7.2,这样做的方法实际上会起作用并且 安全 ?
顺便说一句,我在 localhost
上使用 XAMPP v3.2.4
(我将在生产中转移到 WAMPP
)并且我正在使用 gmail
作为我的邮件服务
你对“现代”思维的认识很差。新的做事方式实际上是使用扩展、框架等...- 可重用代码 是这个快速扩展的 it 世界中的词
早在 90 年代或 80 年代,人们并没有如此广泛地使用或根本没有互联网,如果你想(比方说)在两台计算机(想想 NASA 或其他东西)之间建立连接,你会从头开始编写您自己的协议(POP 或 IMAP)并花费数周甚至数月的时间进行编程。
现在是 2020 年。我们有很多 广泛可用的可重用代码、存储库、open-source 软件等...你明白了
确定您可以在一周内在 php 中编写您自己的身份验证,或者您可以直接下载
Net_Socket (i have 1.2.2) -> https://pear.php.net/package/Net_Socket/download/
Net_SMTP (i have 1.9.2) -> https://pear.php.net/package/Net_SMTP/download/
Mail_extension (I have version 1.4.1) -> https://pear.php.net/package/Mail/download/
使用 7-zip 解压缩所有内容并像这样构建它
你的主文件夹
.Mail-1.4.1
>Mail.php
>Mail
> some default files(dont touch these)
> Net(here you paste files from Net_SMTP and Net_Socket - they should be named SMTP.php and Socket.php)
. sendmail.php
在sendmail.php中你这样写:
//Make sure you made your folder/file structure like you should
require_once "./Mail-1.4.1/Mail.php";
$host = "your-mail-server-of-choice-here";
$port = "465";
$username = "your mail or username";
$password = "your password";
//setting up smtp connection
$smtp = Mail::factory(
'smtp',
array (
'host' => $host,
'port' => $port,
//you don't need this if u are using mail server that doesn't need authentication
'auth' => true,
'username' => $username,
'password' => $password
)
);
$from = "your-mail-here";
$to = "recepient-mail-here";
$subject = "Ay bro!";
$body = "Your message here!";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
exit( "Error happened :( -->".$mail->getMessage() );
}
这很简单吧?如果我们按照您的方式进行,您将花费 很多 的时间和眼泪(是的眼泪)来建立所有这些联系和东西并使其安全等。我希望您满意这个结果!
我想知道如何在 2020 年 php 7.2 中设置自动 SMTP 邮件系统。
我知道 mail()
功能,但它是在初始设置之后出现的。
我在 Whosebug 上看到了关于它的其他问题,但我发布这个问题是因为我只发现 outdated 问题来自 2011[=58] =] 或 2012 和 PHP 从那时起在安全方面和其他方面发生了很大的变化 。
这是我尝试过的:
From what I found I should be changing
ini_set()
inphp.ini
file but there are none ofini_set()
functions there. What I did is I changedsmtp
tosmtp=my-mail-server-of-choice-here
andsmtp_port
tosmtp_port=587
like I was told to.
Also, I should be updating
sendmail.ini
insendmail
folder but (guess what)sendmail folder
doesn't exist -> that also meanssendmail.exe
andsendmail.ini
also don't exist
我也遇到这个错误mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first
这是文件:
$to = 'my-users-mail@some-random.mail';
$subject = "HTML email";
$message = "Hi Bob!";
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html;charset=UTF-8"."\r\n";
$headers .= 'From: my-mail@gmail.com'."\r\n";
mail($to,$subject,$message,$headers);
哪个(根据我读到的)应该可以从 ini_set()
修复 php.ini
文件中的任何地方 - 我猜 bc 只有提供过时的解决方案
什么是 现代 标准,php 7.2,这样做的方法实际上会起作用并且 安全 ?
顺便说一句,我在 localhost
上使用 XAMPP v3.2.4
(我将在生产中转移到 WAMPP
)并且我正在使用 gmail
作为我的邮件服务
你对“现代”思维的认识很差。新的做事方式实际上是使用扩展、框架等...- 可重用代码 是这个快速扩展的 it 世界中的词
早在 90 年代或 80 年代,人们并没有如此广泛地使用或根本没有互联网,如果你想(比方说)在两台计算机(想想 NASA 或其他东西)之间建立连接,你会从头开始编写您自己的协议(POP 或 IMAP)并花费数周甚至数月的时间进行编程。
现在是 2020 年。我们有很多 广泛可用的可重用代码、存储库、open-source 软件等...你明白了
确定您可以在一周内在 php 中编写您自己的身份验证,或者您可以直接下载
Net_Socket (i have 1.2.2) -> https://pear.php.net/package/Net_Socket/download/ Net_SMTP (i have 1.9.2) -> https://pear.php.net/package/Net_SMTP/download/ Mail_extension (I have version 1.4.1) -> https://pear.php.net/package/Mail/download/
使用 7-zip 解压缩所有内容并像这样构建它
你的主文件夹
.Mail-1.4.1
>Mail.php
>Mail
> some default files(dont touch these)
> Net(here you paste files from Net_SMTP and Net_Socket - they should be named SMTP.php and Socket.php)
. sendmail.php
在sendmail.php中你这样写:
//Make sure you made your folder/file structure like you should
require_once "./Mail-1.4.1/Mail.php";
$host = "your-mail-server-of-choice-here";
$port = "465";
$username = "your mail or username";
$password = "your password";
//setting up smtp connection
$smtp = Mail::factory(
'smtp',
array (
'host' => $host,
'port' => $port,
//you don't need this if u are using mail server that doesn't need authentication
'auth' => true,
'username' => $username,
'password' => $password
)
);
$from = "your-mail-here";
$to = "recepient-mail-here";
$subject = "Ay bro!";
$body = "Your message here!";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
exit( "Error happened :( -->".$mail->getMessage() );
}
这很简单吧?如果我们按照您的方式进行,您将花费 很多 的时间和眼泪(是的眼泪)来建立所有这些联系和东西并使其安全等。我希望您满意这个结果!