在本機用phpmailer發送郵件問題
我在本機上用的WampServer Version 2.1版本作為php伺服器,來測試phpmailer發送郵件。我下載了最新的class.phpmailer.php和class.smtp.php檔案,建立了個php檔案phpmail.php來測試發送郵件功能,代碼如下:
require_once('class.phpmailer.php');
include("class.smtp.php");
$mail = new PHPMailer(); //建立郵件發送類
$address = $_POST['address'];
$mail->SMTPDebug=true ;
$mail->IsSMTP(); // 使用SMTP方式發送
$mail->CharSet = "UTF-8"; //chinese;
$mail->Host = "smtp.163.com"; // 局smtp伺服器
$mail->SMTPAuth = true; // 啟用SMTP驗證功能
$mail->Username = "cnmhg168"; // 使用者名稱(請填寫完整的email地址)
$mail->Password = "******"; // 密碼
$mail->From = "[email protected]"; //郵件寄件者email地址
$mail->FromName = "化工網";
$mail->AddAddress("[email protected]", "tttt");//收件者地址
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
$mail->Subject = "PHPMailer測試郵件"; //郵件標題
$mail->Body = "Hello,這是測試郵件,百度"; //郵件內容
$mail->AltBody = "from 火星"; //附加資訊,可以省略
//$mail->SMTPDebug;
if(!$mail->Send())
{
echo "郵件發送失敗.
";
echo "錯誤原因: " . $mail->ErrorInfo;
exit;
}
echo "郵件發送成功";
?>
使用者名稱和密碼沒問題,但是提示如下錯誤資訊,不知道哪裡有問題,求大家給解決下?
( ! ) Notice: Undefined index: address in D:\wamp\www\PHPMailer\phpmail.php on line 6
Call Stack
# Time Memory Function Location
1 0.0041 373128 {main}( ) ..\phpmail.php:0
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 163.com Anti-spam GT for Coremail System (163com[20121016]) "
SMTP -> get_lines(): $data is "220 163.com Anti-spam GT for Coremail System (163com[20121016]) "
SMTP -> FROM SERVER:220 163.com Anti-spam GT for Coremail System (163com[20121016])
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-mail "
SMTP -> get_lines(): $data is "250-mail "
SMTP -> get_lines(): $data was "250-mail "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-mail 250-PIPELINING "
SMTP -> get_lines(): $data was "250-mail 250-PIPELINING "
SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN "
SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN "
SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN "
SMTP -> get_lines(): $str is "250-AUTH=LOGIN PLAIN "
SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN "