按照本教程,我能够发送邮件链接文本。
使用 Gmail 和 PHPMailer 发送电子邮件 新的自动更新生成器已经准备就绪,OCRALight 已经完成了很长时间,并且在更新生成中已经对这个和那个进行了一些改进。
这个过程相当复杂,它涉及逆向工程、数据挖掘、打包、分发以及与我和最终的 Linux 解放之间的蹩脚 Windows 服务器作斗争。
道路上的每一步都被自动化,一步一步,每一个问题都被解决和打磨,现在最后一块已经在他的位置上,自动生成电子邮件。现在将每天进行更新,甚至在周末和假期发送。
如果您对技术方面感兴趣,请继续阅读:
它是如何完成的:
首先,您需要有支持 OpenSSL 的 PHP,对于 Windows,您需要安装 PHP 并在组件列表中仔细选择 OpenSSL,如果您已经安装了 PHP,请不要担心重新安装会保留您的配置,您将能够选择 OpenSSL。
然后下载PHPMailer, 并将其提取到您的主 php 文件附近。
您将需要一个 Gmail 帐户(显然)我建议您为此创建一个新帐户,主要是因为配置需要非常精确,并且您无法在不丢失功能或冒险的情况下自由使用它打破配置。
将您的 Gmail 帐户配置为使用 POP 邮件,但不使用 IMAP,仅使用 POP,仅使用 POP。
现在代码:
<?php
require(”PHPMailer/class.phpmailer.php”);
$update_emails = array(
‘Juan Perez’ => ‘Juan_Perez@jalisco.gob.mx’,
‘Francisco Garcia’ => ‘fgarcia@hotmail.com’,
‘Diana la del Tunel’ => ‘diana@gmail.com’
);
echo “\nSending Update Email\n”;
$mail = new PHPMailer(); // Instantiate your new class
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = “smtp.gmail.com”; // specify main and backup server
$mail->SMTPSecure= ’ssl’; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected
$mail->Username = “youremail@gmail.com”; // SMTP username, you could use your google apps address too.
$mail->Password = “yaourextremelynotlamepassword”; // SMTP password
$mail->From = “youremail@gmail.com”; //Aparently must be the same as the UserName
$mail->FromName = “Your name”;
$mail->Subject = ‘The subject’;
$mail->Body = “The body of your message”;
foreach ($update_emails as $name => $email) {
$mail->AddBcc($email, $name);
}
if(!$mail->Send())
{
echo “There was an error sending the message:” . $mail->ErrorInfo;
exit;
}
echo “Done…\n”;
?>
在这段代码中,我将电子邮件发送给一群人,因此我使用“密件抄送:”字段而不是“收件人:”字段来添加“收件人:”,您将使用 AddAddress($email, $name)。
可能的升级是使用 MySQL 数据库来存储地址, 并提供一个 Web 界面来添加和删除它们。目前,这已经足够了。
记住:PHP 与 OpenSSL;PHP邮件程序;创建一个 Gmail 帐户;激活POP主机:smtp.gmail.com;SMTPAuth=真;SMTPSEcure=ssl; 端口:465;具有域的用户;密码; $Mail->send();