【发布时间】:2017-03-11 08:43:15
【问题描述】:
我正在尝试使用 PHPMailer 发送带有附件的 SMTP 安全邮件。
我用 PHPMailer 库制作了这个函数
public function sendCsv($subject,$body,$path,$mail_to,$from_name,$from_mail,$replyto){
require getcwd() .'/lib/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'tester@mydomain.com';
$mail->Password = '**************';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom($from_mail, $from_name);
$mail->addAddress($mail_to);
$mail->addReplyTo($replyto, 'no reply');
$mail->addAttachment($path);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo $error;
} else {
$sucess = 'Mail sent!';
echo $sucess;
}
}
现在如果我评论 $mail->isSMTP();它工作正常。但我认为它不是 SMTP 安全的。否则我会收到此消息:“邮件错误:SMTP 连接()失败。”
我搜索了这个问题,但没有得到我正在寻找的正确答案。请帮帮我。
我正在使用 HTACCESS 保护的开发服务器工作
【问题讨论】:
-
您使用的是旧版本的 PHPMailer,您需要read the docs。另外,发帖前先搜索一下,这个问题有很多重复的。