1 下载组件
$ composer require "swiftmailer/swiftmailer:^6.0"
2 利用php进行发送
第一种方法利用smtp
require_once '/path/to/vendor/autoload.php';// Create the Transport$transport = (new Swift_SmtpTransport('smtp.example.org', 25)) ->setUsername('your username') ->setPassword('your password');// Create the Mailer using your created Transport$mailer = new Swift_Mailer($transport);// Create a message$message = (new Swift_Message('Wonderful Subject')) ->setFrom(['john@doe.com']) ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name']) ->setBody('Here is the message itself') ;// Send the message$result = $mailer->send($message);
第二种方法利用sendmail本地发送,前提是你的服务器已经安装好sendmail组件
// Sendmail$transport = new Swift_SendmailTransport('/usr/sbin/sendmail -bs');