天天看點

使用phpmailer發送email

http://phpmailer.codeworxtech.com/

這裡下載下傳phpmailer

<html>

<head>

<title>使用PHPMailer發郵件</title>

</head>

<body>

<?php

 if (!array_key_exists('Submitted',$_POST))

 {

?>

    <form method="post" action="mail2.php">

    <input type="hidden" name="Submitted" value="true"/><br/>

    郵件伺服器: <input type="text" name="Host" size="25"/><br/>

    如果要求驗證:<br/>

    使用者名: <input type="text" name="Username" size="25"/><br/>

    密    碼: <input type="password" name="Password" size="10"/>

    <hr/>

    發給: <input type="text" name="To" size="25"/><br/>

    來自 Email: <input type="text" name="From" size="25"/><br/>

    來自 姓名: <input type="text" name="FromName" size="25"/><br/>

    主題: <input type="text" name="Subject" size="25"/><br/>

    <textarea name="Message" cols="50" rows="10"></textarea><br/>

    使用HTML: <input type="checkbox" name="HTML"/>

    <input type="submit" value="發送Email"/>

    </form>

 }

 else

    require("class.phpmailer.php");

    $To = $_POST['To'];

    $From = $_POST['From'];

    $FromName = $_POST['FromName'];

    $Subject = $_POST['Subject'];

    $Message = $_POST['Message'];

    $Host = $_POST['Host'];

    if (array_key_exists('HTML',$_POST))

    {

     $HTML = true;//HTML格式

    }

    else

     $HTML = false;//純文字

    $Mail = new PHPMailer();

    $Mail->IsSMTP(); // 通過SMTP發送

    $Mail->Host = $Host; //SMTP伺服器

    if (array_key_exists('Username',$_POST))

     $Mail->SMTPAuth=true;

     $Mail->Username=$_POST['Username'];

     $Mail->Password=$_POST['Password'];//實際中這裡肯定需要做安全處理     

     $Mail->SMTPAuth=false;

    } 

    $Mail->From = $From;

    $Mail->FromName = $FromName;

    $Mail->AddAddress($To);

    $Mail->AddReplyTo($From);

    $Mail->WordWrap = 50; //設定自動換行

    $Mail->IsHTML($HTML);

    $Mail->Subject    = $Subject;

    $Mail->Body = $Message;

    $Mail->CharSet = "gbk";//中文字元集

    if($Mail->Send())

     echo "消息已發送";

        echo "消息未發送<br/>";

        echo "Mailer錯誤: " . $Mail->ErrorInfo;

</body>

</html>

  本文轉自 xcf007 51CTO部落格,原文連結:http://blog.51cto.com/xcf007/140404,如需轉載請自行聯系原作者

繼續閱讀