编程语言
首页 > 编程语言> > php 程序发送谷歌邮件

php 程序发送谷歌邮件

作者:互联网

一、安装 PHPMailer扩展

二、获取谷歌邮箱应用程序码

参考下面官方文档

https://support.google.com/accounts/answer/185833
 

三、php代码

/**
 * todo 谷歌账号 系统发邮件
 * @param array $tomail 接收邮件者邮箱
 * @param string $subject 邮件主题
 * @param string $body 邮件内容
 * @param string $attachment 附件列表
 * @return boolean
 */
function send_gmail($toMail, $subject = '', $body = '', $attachment = null)
{
    $mail = new \PHPMailer\PHPMailer\PHPMailer();
     //实例化PHPMailer对象
    $mail->IsSMTP();
    $mail->CharSet = "UTF-8";
    $mail->Encoding = 'base64';
    $mail->SMTPDebug = 0; //是否调试
    $mail->SMTPAuth = true;
    $mail->Host = 'ssl://smtp.gmail.com:465'; //host
    $mail->Port = 25; //端口
    $mail->Username = ""; //发件人邮箱
    $mail->Password = ""; //发件人专用密码
    $mail->SetFrom("","Content System"); //发件人邮箱和名称
    $mail->Subject = $subject; //标题
    $mail->Body = $body; //内容
    $mail->IsHTML(true); //是否启用html
 

    foreach ($toMail as $key => $val){
        $mail->AddAddress($val, $key);
    }
    return $mail->Send() ? true : $mail->ErrorInfo;

}

标签:PHPMailer,谷歌,param,发件人,邮箱,mail,php,邮件,string
来源: https://blog.csdn.net/qq_31812703/article/details/118891670