使用PHPMailer代码在WordPress中发送电子邮件

时间:2016-06-20 12:27:03

标签: php wordpress

我正在尝试在wordpress中发送电子邮件。这段代码工作正常如果我发送简单的php文件的电子邮件,但当我在wordpress中粘贴该文件与此代码时,没有任何反应。我确信有些东西我不知道。

if(isset($_POST['details_submit'])){    

        $mail = new PHPMailer;
        $mail->isSMTP();                            // Set mailer to use SMTP
        $mail->SMTPAuth = true;                     // Enable SMTP authentication
        $mail->Host = $smtp_server;                 // Specify main and backup SMTP servers
        $mail->Username = $username;                 // SMTP username
        $mail->Password = $password;                // SMTP password
        $mail->SMTPSecure = "tls";                  // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                          // TCP port to connect to

        $mail->setFrom("orders@test.com", "Orders Test");

        $mail->addAddress('mark@aol.com', 'Mark');   // Add a recipient

        $mail->isHTML(true);  // Set email format to HTML

        $bodyContent = 'testing message';
        $mail->Subject = 'Hello Checking' ;
        $mail->Body    = $bodyContent;
        $mail->AltBody = $bodyContent;

        if(!$mail->send()) {
            echo "Message could not be sent.";
            $error = '<div class="alert alert-danger"><strong>Mailer Error: '. $mail->ErrorInfo.'</strong></div>';
        } else {
            $error = '<div class="alert alert-success"><strong>Message has been sent</strong></div>';
                }
            }

        }

0 个答案:

没有答案