php使用Swift发送邮件

<?php
	include_once ("Swift.php");
    include_once ("Swift/Connection/SMTP.php");
    include_once ("Swift/Authenticator/LOGIN.php");
    //收件人的地址
    $receive_mail="[email protected]";
    // 创建smtp连接,由于发送邮件的邮箱smtp地址和端口
    $smtp = new Swift_Connection_SMTP('smtp.sina.com', 25);
    // 设置用于发送邮件的邮箱账号
    $smtp->setUsername('[email protected]');
    // 设置发件箱的邮箱登陆密码
    $smtp->setPassword('1qaz2wsx');
    //添加ssl连接支持,如果没此项,发送到gmail等需要ssl连接的邮箱就会失败,但是开启此选项会影响邮件发送的速度
    if(stripos($receive_mail,"@gmail.com")!==false){
    	$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
    }
    $swift = new Swift($smtp);
    //邮件标题
    $title="您收到一封新的求职简历,应聘php程序员的职位";
    //邮件正文
    $content="管理员,您好!您收到一封新的求职简历,应聘php程序员的职位......<br/>";
    $message = new Swift_Message($title, $content, 'text/html', 'base64');
    echo ($swift->send( $message, $receive_mail, new Swift_Address('[email protected]', 'demo_sender')))?'成功':'失败';
?>

 

你可能感兴趣的:(html,PHP,Gmail)