PHPMailer问题 [英] PHPMailer Problems

查看:48
本文介绍了PHPMailer问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我已经下载了 PHP Mailer的类,它需要使用 require_once >然后设置一个发送邮件的功能:

Okay, so I've downloaded PHP Mailer's class, required it using require_once then make a function for sending mail:

public function sendMail($to, $subject, $body) { 
            $mail = new phpmailer;

            $mail->IsSMTP(); // set mailer to use SMTP
            $mail->SMTPAuth = true;
            $mail->Username = 'USERNAME';
            $mail->Password = 'PASSWORD';
            $mail->Port = 465;
            $mail->SMTPSecure = 'SSL';
            $mail->From = "EMAIL";
            $mail->FromName = "FROM NAME";
            $mail->Host = "smtp.gmail.com;";  // specify main and backup server

            if(is_array($to)) {
                foreach($to as $x) {
                    $mail->AddAddress($x);
                }
            } else {
                $mail->AddAddress($to);
            }

            $mail->AddReplyTo("REPLY EMAIL", "REPLY NAME");
            $mail->WordWrap = 50;    // set word wrap

            $mail->IsHTML(true);    // set email format to HTML
            $mail->Subject = $subject;
            $mail->Body = $body;

            if(!$mail->Send()){
                return false;
            }
        }

当我去做(在$ core类中)

And when I go to do (it's in the class $core)

if($core->sendMail('MYEMAIL@gmail.com', 'Something', 'Some body')) {
        echo 'Mail sent';
    } else {
        echo 'Fail';
    }

返回失败.脚本中的代码包含正确的信息,我只是使用占位符将其发布到此处.

It returns fail. The code in the script holds the correct information, I've just used placeholders for posting it here.

推荐答案

$ mail 包含错误消息,请执行以下操作:

$mail contains the error message, do the following:

if (!$mail->Send()) {
    throw new Exception($mail->ErrorInfo);
}

而不是仅返回"false".

instead of just returning "false".

这篇关于PHPMailer问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆