phpmailer 發送gmail帳號

來源:互聯網
上載者:User

Php代碼 
//下面定義一個發送郵件的函數,已經測試通過。   
//$sendto_email:郵件發送地址   
//$subject:郵件主題   
//$body:郵件內文內容   
//$sendto_name郵件接受方的姓名,發送方起的名字。一般可省。  
function stmp_mail($sendto_email, $subject = null, $body = null, $sendto_name = null) { 
     
    vendor ( "PHPMailer.class#phpmailer" ); //匯入函數包的類class.phpmailer.php  
     
 
    $mail = new PHPMailer (); //建立一個郵件發送類對象   
    $mail->IsSMTP (); // send via SMTP  
    $mail->Port = 25; //傳送埠  
    $mail->Host = "ssl://smtp.gmail.com:465"; // SMTP 郵件伺服器地址,這裡需要替換為發送郵件的郵箱所在的郵件伺服器地址, 這裡使用了gmail的SMTP設定 
    $mail->SMTPAuth = true; // turn on SMTP authentication 郵件伺服器驗證開   
    $mail->Username = "leobrilliantlife@gmail.com"; // SMTP伺服器上此郵箱的使用者名稱,有的只需要@前面的部分,有的需要全名。請替換為正確的信箱使用者名   
    $mail->Password = "****"; // SMTP伺服器上該郵箱的密碼,請替換為正確的密碼   
    $mail->From = "leobrilliantlife@gmail.com"; // SMTP伺服器上發送此郵件的郵箱,請替換為正確的郵箱,$mail->Username 的值是對應的。                  
    $mail->FromName = "掌上順德"; // 真實寄件者的姓名等資訊,這雷根據需要填寫   
    $mail->CharSet = "utf-8"; // 這裡指定字元集!   
    $mail->Encoding = "base64"; 
    $mail->AddAddress ( $sendto_email, $sendto_name ); // 收件者郵箱和姓名   
    //$mail->AddReplyTo('sdaping@mail.ustc.edu.cn',"管理員");//這一項根據需要而設   
    //$mail->WordWrap = 50; // set word wrap   
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 附件處理   
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");   
    $mail->IsHTML ( true ); // send as HTML 
    $mail->Subject = $subject; // 郵件主題  
    // 郵件內容 
    $mail->Body = "<html><head>   
            <meta http-equiv=”Content-Language” content=”zh-cn”>   
            <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″></head>   
            <body>'.$body.'</body></html>"; 
    $mail->AltBody = "text/html"; 
    if (! $mail->Send ()) { 
        //郵件發送失敗 
        return false; 
    } else { 
        //郵件發送成功 
        return true; 
    } 
 
} //function end

作者“butter”
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.