【问题标题】:phpmailer error: invalid addressphpmailer错误:地址无效
【发布时间】:2015-10-09 08:54:40
【问题描述】:

我正在尝试使用 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;
}

【问题讨论】:

  • 您的代码基于一个过时的示例,因此请确保您使用的是最新的 PHPMailer,并将您的代码基于提供的 gmail 示例。您已设置 SMTPDebug = 2,但尚未显示生成的输出。

标签: php email smtp gmail phpmailer


【解决方案1】:

试试这个

请写下下面一行。

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

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

我希望这会对你有所帮助。祝你好运

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    相关资源
    最近更新 更多