在本机用phpmailer发送邮件问题
我在本机上用的WampServer Version 2.1版本作为php服务器,来测试phpmailer发送邮件。我下载了最新的class.phpmailer.php和class.smtp.php文件,新建了个php文件phpmail.php来测试发送邮件功能,代码如下:
<?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 = "cnmhg168@163.com"; //邮件发送者email地址
$mail->FromName = "化工网";
$mail->AddAddress("mysimpledesign@163.com", "tttt");//收件人地址
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
$mail->Subject = "PHPMailer测试邮件"; //邮件标题
$mail->Body = "Hello,这是测试邮件,<a href='www.baidu.com'>百度</a>"; //邮件内容
$mail->AltBody = "from 火星"; //附加信息,可以省略
//$mail->SMTPDebug;
if(!$mail->Send())
{
echo "邮件发送失败. <p>";
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 "
SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN "
SMTP -> get_lines(): $str is "250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj "
SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj "
SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj "
SMTP -> get_lines(): $str is "250-STARTTLS "
SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj 250-STARTTLS "
SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj 250-STARTTLS "
SMTP -> get_lines(): $str is "250 8BITMIME "
SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj 250-STARTTLS 250 8BITMIME "
SMTP -> FROM SERVER: 250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFy-od-UCa0xDrUUUUj 250-STARTTLS 250 8BITMIME
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 dXNlcm5hbWU6 "
SMTP -> get_lines(): $data is "334 dXNlcm5hbWU6 "
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 "
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 "
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "535 Error: authentication failed "
SMTP -> get_lines(): $data is "535 Error: authentication failed "
SMTP -> ERROR: Password not accepted from server: 535 Error: authentication failed
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 OK "
SMTP -> get_lines(): $data is "250 OK "
SMTP -> FROM SERVER:250 OK
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "553 authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188 "
SMTP -> get_lines(): $data is "553 authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188 "
SMTP -> FROM SERVER:553 authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
SMTP -> ERROR: MAIL not accepted from server: 553 authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
The following From address failed: cnmhg168@163.com : MAIL not accepted from server,553,authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
SMTP server error: authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
邮件发送失败.
错误原因: The following From address failed: cnmhg168@163.com : MAIL not accepted from server,553,authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
SMTP server error: authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
SMTP server error: authentication is required,smtp7,C8CowEDp+0krXixR8VKFBg--.1256S3 1361862188
[解决办法]
Notice: Undefined index: address in D:\wamp\www\PHPMailer\phpmail.php on line 6
是说 $address = $_POST['address']; 中的 $_POST['address'] 不存在
也就是说,你的程序不是通过表单提交运行的,或者是表单中没有名为 address 的控件
[解决办法]
$address = $_POST['address'];
传递post参数了么?
[解决办法]
$mail->SMTPSecure = "tls"; //加上这句试试
此外,你的phpmailer 是不是最新的