php swiftmailer 发送邮件文档
//邮箱配置 $config =array( 'MAIL_PORT'=>25,//端口号 'MAIL_HOST'=>'smtp.qq.cn',//smtp服务器的名称 'MAIL_SMTPAUTH'=>1,//1是 0否 启用smtp认证 'MAIL_USERNAME'=>'[email protected]',//邮箱地址 'MAIL_PASSWORD'=>'A123456',//邮箱密码 'MAIL_FROM'=>'[email protected]',//发送邮箱地址 'MAIL_FROMNAME'=>'神马都要问',//发件人姓名 'MAIL_ISHTML'=>1,//1是 0否HTML格式邮件 'MAIL_CHARSET'=>'utf-8',//邮箱编码 );
$transport = Swift_SmtpTransport::newInstance($config['MAIL_HOST'], $config['MAIL_PORT'])//设置服务器地址与端口 ->setUsername($config['MAIL_USERNAME'])//设置邮箱账号 ->setPassword($config['MAIL_PASSWORD'])//设置邮箱密码 ; $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance() ->setFrom(array($config['MAIL_USERNAME'] => $config['MAIL_FROMNAME']))//设置发送邮件人地址与名称 ->setto(array('[email protected]'))//接收人邮件,可以多个 -> setSubject('123')//邮件标题 -> setBody('Here is the message itself', 'text/html', 'utf-8');//邮件内容 $fasss = array(); try{ if($mailer -> send($message,$fasss)){ echo 'ok'; }else{ echo 'error'; } }catch (Swift_RfcComplianceException $e){ echo '邮件发送失败: ' . $e -> getMessage(); }