PHPMailer發送郵件範例程式碼

來源:互聯網
上載者:User
PHPMailer 是一個強大的 PHP 編寫的郵件發送類,使用它可以更加便捷的發送郵件,並且還能發送附件和 HTML 格式的郵件,同時還能使用 SMTP 伺服器來發送郵件。本文給大家分享PHPMailer發送郵件功能,一起看看吧

HTML

首先我們先放置一個收件匣的輸入框和一個發送郵件按鈕:

收件者:

<input type="text" class="input_text" id="email" name="email" value="@"/> <input type="button" class="btn" id="send" value="發送"/>jQuery$(function() {   $("#send").click(function() {     var email = $("#email").val();    $("#send").addClass("loading").val("loading...").attr("disabled", "disabled");    $.post("ajax.php",{       "email": email     },    function(data) {       if (data == 1){         $("#result").html("發送成功,請注意查收您的郵件!");      } else {         $("#result").html(data);      }       $("#send").removeAttr("disabled").removeClass("loading").val("發送");     });  }); });
Ajax.phprequire_once('class.phpmailer.php'); $address = $_POST['email']; //收件者email $mail = new PHPMailer();//執行個體化 $mail->IsSMTP(); // 啟用SMTP$mail->Host = "smtp.163.com";//SMTP伺服器 以163郵箱為例子$mail->Port = 25; //郵件傳送埠 $mail->SMTPAuth = true; //啟用SMTP認證 $mail->CharSet = "UTF-8"; //字元集$mail->Encoding = " 64";//編碼方式$email_system = "hjl416148489_3@163.com";$mail->Username = $email_system; //你的郵箱 $mail->Password = ""; //你的密碼 $mail->Subject = "你好";//郵件標題 $mail->From = $email_system; //寄件者地址(也就是你的郵箱) $mail->FromName = "素材火"; //寄件者姓名 $mail->AddAddress($address, "親");//添加收件者(地址,暱稱) $mail->AddAttachment('send.xls', '我的附件.xls');// 添加附件,並指定名稱 $mail->IsHTML(true);//支援html格式內容 $mail->Add dedImage("logo.jpg", "my-attach", "logo.jpg");//設定郵件中的圖片 $mail->Body = '你好, <b>朋友</b>! <br/>這是一封來自<a href="http://www.erdangjiade.com" target="_blank">erdangjiade.com</a>的郵件!<br/><img alt="erdangjiade" src="cid:my-attach">'; //郵件主體內容 //發送 if (!$mail->Send()) {  echo "發送失敗: " . $mail->ErrorInfo;}else{   echo "1";}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.