郵件api接口文件在附件中
因爲很多地方都可能用到發郵件技術,所以封裝成方法方便其他地方調用
function send_mail($address, $subject, $content){ vendor('PhpMailer.PHPMailerAutoload'); $mail = new PHPMailer; $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.aliyun.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'xxxxx'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 1234; // TCP port to connect to $mail->setFrom('[email protected]', 'xxxx'); $mail->addAddress($address, 'Joe User'); // Add a recipient // $mail->addAddress('[email protected]'); // Name is optional // $mail->addReplyTo('[email protected]', 'Information'); // $mail->addCC('[email protected]'); // $mail->addBCC('[email protected]'); // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->isHTML(true); // Set email format to HTML $mail->CharSet='UTF-8'; $mail->Subject = $subject; $mail->Body = $content; // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { return false; } else { return true; } }
api接口文件路徑放置: