我有一個問題,我想從你那里得到一些提示。我有一個公司電子郵件 @example.info,與我在 Godaddy 上托管的 example.info 網站有關。我在谷歌上搜索過,但沒有找到任何關于此事的指南,如何在我的 centos 8 服務器上創建一個 php 代碼,以便在我決定時發送預設時事通訊?1- 我只需要知道是否可以將我的 php 代碼鏈接到 @example.info 外部電子郵件以及如何操作。2- 此外,我需要知道如何向 8000 多人發送時事通訊,而不會被谷歌或其他此類問題作為垃圾郵件輸入。我選擇這個解決方案是因為我在互聯網上發現 gmail 不允許你自動發送超過 100 封電子郵件或類似的東西,所以我創建了自己的電子郵件來做同樣的事情,但繞過了限制。歡迎任何可以向我解釋如何做或鏈接我指南的人。謝謝
uj5u.com熱心網友回復:
您可以使用 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);
}
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/400672.html
