如何在您的 centos 8 服务器和外部服务上设置通过 php 代码发送的时事通讯

How to set up a newsletter sent via php code on your centos 8 server and an external service

我有一个问题,我想从你那里得到一些提示。我有一个公司电子邮件 @ example.info 与我在 godaddy 上托管的 example.info 网站有关。我在 google 上搜索过,但我没有找到任何关于此事的指南,我如何在我的 centos 8 服务器上创建一个 php 代码,在我决定时发送预设时事通讯? 1- 我只需要知道是否可以将我的 link 我的 php 代码发送到@ example.info 外部电子邮件以及如何操作。 2- 此外,我需要知道如何向超过 8000 人发送时事通讯而不被 google 或其他此类问题输入为垃圾邮件。 我选择这个解决方案是因为我在互联网上发现 gmail 不允许你自动发送超过 100 封电子邮件或类似的东西,所以我创建了我自己的电子邮件来做同样的事情但绕过了限制。 欢迎任何可以向我解释如何做或 link 给我指导的人。谢谢

您可以使用 phpmailer 库轻松地通过外部 SMTP 服务器发送邮件,但如果您不想使用 phpmailer,请使用以下 PHP 函数:

<?php  

function authMail($from, $namefrom, $to, $nameto, $subject, $message){
/*  your configuration here  */

$smtpServer = "XX.XX.XX.XXXX"; //ip accepted as well
$username = "xxxxxxx"; //the login for your smtp
$password = "xxxxxxx"; //the pass for your smtp


$port = "25"; // should be 25 by default
$timeout = "60"; //typical timeout. try 45 for slow servers

$localhost = "127.0.0.1"; //this seems to work always
$newLine = "\r\n"; //var just for nelines in MS
$secure = 0; //change to 1 if you need a secure connect
  
/*  you shouldn't need to mod anything else */

//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
   $output = "Failed to connect: $smtpResponse";
   return $output;
}
else
{
   $logArray['connection'] = "Connected to: $smtpResponse";
}

//say HELO to our little friend
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse'] = "$smtpResponse";

//start a tls session if needed 
if($secure)
{
   fputs($smtpConnect, "STARTTLS". $newLine);
   $smtpResponse = fgets($smtpConnect, 4096);
   $logArray['tlsresponse'] = "$smtpResponse";

   //you have to say HELO again after TLS is started
   fputs($smtpConnect, "HELO $localhost". $newLine);
   $smtpResponse = fgets($smtpConnect, 4096);
   $logArray['heloresponse2'] = "$smtpResponse";
}

//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";


//email to
fputs($smtpConnect, "RCPT TO: $to" . $newLine);

$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";

//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=utf-8" . $newLine;
//$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;


//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success 
return($logArray);
}


?>