duanping2809 2015-01-05 04:50
浏览 44

无法使用phpmailer发送邮件

can someone help me to find what is wrong with the following code that i used to send mail in php.

error_reporting(E_STRICT);
date_default_timezone_set('asia/kolkata');
require_once('class.phpmailer.php');
$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "manikandan@gmail.com";
$mail->Password = "mypassword";
$mail->From = ("manikandan@gmail.com");
$mail->SetFrom("manikandan");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("peter1991@gmail.com");
 if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }

?>

i am getting the following error:- 2015-01-05 04:32:10 Invalid address: manikandan i am using php 5.2.2 ,Apache 2.0 Handler in windows.

  • 写回答

3条回答 默认 最新

  • douduocuima61392 2015-01-05 04:58
    关注

    setFrom expects an email address as the first parameter. Try:

    $mail->setFrom('manikandan@gmail.com');
    

    If you also want to set a proper name, use the second parameter

    $mail->setFrom('manikandan@gmail.com', 'John Smith');
    

    http://phpmailer.github.io/PHPMailer/classes/PHPMailer.html#method_setFrom

    Also, I think you should be using the autoloader instead of including the PHPMailer class directly.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度