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')))?'成功':'失敗';
?>

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章