Phpmailer错误:无效的地址


phpmailer error: invalid address

我试图用php建立一个邮件函数,但它只是显示"无效地址:"执行后。请求帮助。

下面是我的代码:
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer();  // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2;  // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;  // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; 
$mail->Username = 'myemail@gmail.com';  
$mail->Password = 'mypassword';   
$mail->From = "myemail@gmail.com";
$mail->FromName = "Web Site";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addAddress('myfriend@gmail.com');
$mail->AddReplyTo('myfriend@gmail.com');
if(!$mail->Send()) {
    $error = 'Mail error: '.$mail->ErrorInfo; 
    return false;
} else {
    $error = 'Message sent!';
    return true;
}

Try This

请写出下面一行。

$mail->CharSet = "UTF-8"; // To support special characters in SMTP mail 
//$mail->SMTPDebug = 2; Comment this line of code
我希望这对你有帮助。祝你好运