我正在尝试使用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;
}
答案 0 :(得分:2)
试试这个
请写下面的一行。
$mail->CharSet = "UTF-8"; // To support special characters in SMTP mail
//$mail->SMTPDebug = 2; Comment this line of code
我希望这会对你有所帮助。祝你好运