shell 发送邮件

yum -y install sendmail

systemctl start sendmail.service

echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt

certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt

set smtp="smtps://smtp.163.com:465"
set from="xxx@163.com"
set smtp-auth=login
set smtp-auth-user="xxx@163.com"
set smtp-auth-password="xxx" //此处是授权码 不是秘密
set ssl-verify=ignore
set nss-config-dir=/root/.certs //证书路径

echo hello | mail -s "TEST" 1277600680@qq.com

   $mail = new PHPMailer(true);
    try {
        $mail->isSMTP();                                            //Send using SMTP
        $mail->Host = 'smtp.163.com';                     //Set the SMTP server to send through
        $mail->SMTPAuth = true;                                   //Enable SMTP authentication
        $mail->Username = 'shibcogame@163.com';                      //SMTP username
        $mail->Password = 'ZMRFQMMNIXIVAG';                               //SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
        $mail->Port = 465;

        $mail->setFrom('shibcoingme@163.com');
        $mail->addAddress('127700680@qq.com');               //Name is optional

        $mail->isHTML(true);                                  //Set email format to HTML
        $code = rand(111111, 999999);
        $mail->Subject = 'Your verification code is' . $code;

        $mail->send();
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容