【问题标题】:How to set up a newsletter sent via php code on your centos 8 server and an external service如何在您的 centos 8 服务器和外部服务上设置通过 php 代码发送的时事通讯
【发布时间】:2022-01-01 17:17:12
【问题描述】:

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

【问题讨论】:

  • 你的问题可以更集中吗? (1)使用php mail发送HTML格式的邮件(或使用phpmailer); (2) - 使用 SMTP 服务器发送电子邮件 - 这可以在 phpmailer 中轻松设置; [请通过谷歌学习如何设置SMTP邮件] (3)如果您使用自己的SMTP服务器,则发送的邮件数量没有限制; (4) 确保您不是真的发送垃圾邮件,否则您的服务器也会被列入黑名单(当许多收件人抱怨时)
  • 我的问题是,你如何从 php 连接到我的邮件服务器 @example.info?我没有在互联网上找到指导和关注,只有关于 gmail 或类似的指南。谢谢
  • 我明白了。那请看我的回答

标签: php email smtp newsletter centos8


【解决方案1】:

您可以使用 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);
}


?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 2011-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多