完美联系我们表格问题[复制]

问题描述 投票:0回答:1

这个问题在这里已有答案:

有没有人使用forest_of_code / PerfectCode的“Perfect Contact Us Form”?

我不断收到错误:“糟糕!有些事情不对。请查看您的详细信息。”

我一步一步地按照编码器的指示,多次检查我没有错误输入soemthing。我也确定我的主机允许通过SMTP发送邮件。我正在尝试使用gmail smtp发送邮件。我在我的帐户上启用了“允许安全性较低的应用”,而我没有使用2AuthFactor。

这些是我当前的设置(XXXX是隐藏我的信息,在我的文件中使用我的实际信息):

function smtpContact($to, $subject, $name, $phone, $message){
            require_once 'PHPMailer/PHPMailerAutoload.php';
            $response = array();
            //Create a new PHPMailer instance
            $mail = new PHPMailer;
            $mail->isSMTP();
            $mail->SMTPDebug = 0;
            $mail->Debugoutput = 'html';
            $mail->Host = "smtp.gmail.com";
            $mail->Port = 587;
            $mail->SMTPAuth = true;
            $mail->Username = "[email protected]";
            $mail->Password = "xxxxxxxxxxxxx";
            $mail->setFrom($to, $name);
            $mail->addAddress('[email protected]', 'XXXXX');
            $mail->Subject = $subject;
            $message =  '<div  style="background:#F5F5F5; padding:10px;">
                            <p>'.$message.'</p><br />
                            <div>Name : '.$name.'</div><br />
                            <div>Phone : '.$phone.'</div><br />
                        </div>';
            $mail->msgHTML($message);
            $mail->AltBody = 'This is a plain-text message body';
            $mail->SMTPOptions = array(
                'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        ); 
        if (!$mail->send()){
            // For Debugging
            //return "Mailer Error: " . $mail->ErrorInfo;
            $response['error'] = 'Something not right. Please check your details.';
        }else{
            $response['success'] = 'Your email has been sent successfully.';
        }
        echo json_encode($response, JSON_PRETTY_PRINT);
    }/*...ends[contactus]...*/
php email contact-form
1个回答
0
投票

大约5年前就已经回答了这个问题。我正在发布这个,只是因为人们仍然像我一样遇到这个问题。我在这里找到了解决方案:send email using Gmail SMTP server through PHP Mailer

基本上我所要做的就是删除这行$mail->isSMTP();

我很感激那位用户,我一直在寻找解决方案好几天,直到我偶然发现他的问题,他自己回答:D

© www.soinside.com 2019 - 2024. All rights reserved.