简体   繁体   English

phpmailer错误:地址无效

[英]phpmailer error: invalid address

I am trying to build a mail function with php, but it's justing showing " Invalid address :" after execute. 我正在尝试使用php构建邮件功能,但执行后仅显示“ Invalid address :”。 Pleas help. 请帮助。

Below is my code: 下面是我的代码:

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 尝试这个

Please write the below line. 请写以下行。

$mail->CharSet = "UTF-8"; // To support special characters in SMTP mail 

//$mail->SMTPDebug = 2; Comment this line of code

I hope this will help you. 我希望这能帮到您。 Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM