PHPMailer,没有错误

PHPMailer,没有错误,php,phpmailer,captcha,contact-form,Php,Phpmailer,Captcha,Contact Form,谢谢你回答我的问题 我正试图在远程托管的网站上建立一个联系表单 我希望表单具有验证码2,并在验证码测试成功后发送邮件。对于我使用“PHPMailer”的邮件部分,验证码有效,脚本没有返回错误,但没有收到邮件 我尝试过使用谷歌邮件服务器,但没有成功。谁能看出我做错了什么?以下是我的php代码: <?php $privkey = "xxxx"; if (isset($_POST['submit'])) { $url = 'https://www.google.com/re

谢谢你回答我的问题

我正试图在远程托管的网站上建立一个联系表单

我希望表单具有验证码2,并在验证码测试成功后发送邮件。对于我使用“PHPMailer”的邮件部分,验证码有效,脚本没有返回错误,但没有收到邮件

我尝试过使用谷歌邮件服务器,但没有成功。谁能看出我做错了什么?以下是我的php代码:

<?php
$privkey = "xxxx";
if (isset($_POST['submit'])) {
    $url        = 'https://www.google.com/recaptcha/api/siteverify';
    $response   = file_get_contents($url."?secret=". $privkey . "&response=" . $_POST['g-recaptcha-response'] ."&remoteip=" .$_SERVER['REMOTE_ADDR']);
    $data       = json_decode($response);

    if (isset($data->success) AND $data->success == true) {
        //VERIFIED CAPTCHA
        date_default_timezone_set('Europe/Amsterdam');
        require '../scripts/phpmailer/PHPMailerAutoload.php';
        if (isset($_POST['email'])) {
            // validation expected data exists
            if (!isset($_POST['first_name']) ||
                !isset($_POST['last_name']) ||
                !isset($_POST['email']) ||
                !isset($_POST['telephone']) ||
                !isset($_POST['comments'])) {
                died('Er is een probleem met de volledigheid van de informatie in uw contactformulier.'); //kill script
            }
            // var's for mailing based upon post input
            $first_name = $_POST['first_name']; // required 
            $last_name  = $_POST['last_name']; // required 
            $email_from = $_POST['email']; // required 
            $telephone  = $_POST['telephone']; // not required 
            $comments   = $_POST['comments']; // required

            // _POST DATA VALIDATION
            $error_message = "";
            // email
            $email_exp     = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD';
            if (!preg_match($email_exp, $email_from)) {
                $error_message .= 'Het e-mailadres is niet geldig.<br />';
            }

            // NAME VALIDATION
            $string_exp = "/^[A-Za-z .'-]+$/";
            // first name
            if (!preg_match($string_exp, $first_name)) {
                $error_message .= 'Uw voornaam bevat niet toegestane leestekens.<br />';
            }
            // last name
            if (!preg_match($string_exp, $last_name)) {
                $error_message .= 'Uw achernaam bevat niet toegestane leestekens.<br />';
            }

            // message
            if (strlen($comments) < 2) {
                $error_message .= 'Het bericht is niet valide.<br />';
            }
            // STOP SCRIPT IF ERROR IS >0
            if (strlen($error_message) > 0) {
                died($error_message);
            }

            $email_message = "Bericht en gegevens hieronder.\n\n";

            function clean_string($string)
            {
                $bad = array(
                    "content-type",
                    "bcc:",
                    "to:",
                    "cc:",
                    "href"
                );
                return str_replace($bad, "", $string);
            }

            $email_message .= "First Name: " . clean_string(stripslashes($first_name)) . "\n";
            $email_message .= "Last Name: " . clean_string(stripslashes($last_name)) . "\n";
            $email_message .= "Email: " . clean_string(stripslashes($email_from)) . "\n";
            $email_message .= "Telephone: " . clean_string(stripslashes($telephone)) . "\n";
            $email_message .= "Comments: " . clean_string(stripslashes($comments)) . "\n";

            $mail = new PHPMailer;
            $mail->SMTPDebug = 3; // Enable verbose debug output
            $mail->isSMTP(); // Set mailer to use SMTP
            $mail->Host       = 'smtp.transip.email'; // Specify main and backup SMTP servers
            $mail->SMTPAuth   = true; // Enable SMTP authentication
            $mail->Username   = '****@amplitudemusic.nl'; // SMTP username
            $mail->Password   = '*****'; // SMTP password
            $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
            $mail->Port       = 465; // TCP port to connect to
            $mail->setFrom('****@amplitudemusic.nl', 'name'); // Sender address
            $mail->addAddress('****@amplitudemusic.nl', 'name'); // Recipient 1
            $mail->addAddress('danny@amplitudemusic.nl', 'name'); // Recipient 2
            $mail->addReplyTo('****@amplitudemusic.nl', '{clean_string($first_name)} {clean_string($last_name)}'); // Reply Address

            $mail->Subject = 'contactformulier website';
            $mail->AltBody = '{$email_message}';

            if (!$mail->send()) {
                echo 'Message could not be sent.';
                echo 'Mailer Error: ' . $mail->ErrorInfo;
                header('location: contact.php?CaptchaPass=True');
            } else {
                //not verified
                header('location: contact.php?CaptchaFail=True');
            }
        }
    }
}
?>
<html lang=nl>
<head>
    <meta charset="utf-8">

    <title>Amplitude | Drive in Disco</title>

    <meta name="description" content="">

  <!-- Mobile-friendly viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

   <!-- Style sheet link -->
    <link href="../css/reset.css" rel="stylesheet" media="all">
    <link href="../css/main.css" rel="stylesheet" media="all">
    <script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body background="../img/background_website.png">
    <div id="background">
        <header role="banner" src="../index.php">
            <a href="../index.php" alt="Amplitude-Header"><img id="brand" src="../img/transparent.gif"/></a>
            <nav role="navigation" position="relative">
                <ul class="navbar" >
                    <li><a href="../index.php">Home</a></li>
                    <li><a href="prijzen.php">Prijzen</a></li>
                    <li><a href="contact.php">Contact</a></li>

                </ul>
            </nav>
        </header>
        <h2>Contact formulier</h2>
            <?php
if (isset($_GET['CaptchaPass'])) {
?>
               <h1>Uw mail is succesvol verzonden.</h1>
            <?php
}
?>
           <?php
if (isset($_GET['CaptchaFail'])) {
?>
               <h1>You did not pass the spam validator. Please try again.</h1>
            <?php
}
?>

我的问题是初始化“$mail=new PHPmailer;”后参数传递给PHPmailer的顺序

应该是:

$mail = new PHPMailer;
$mail->SMTPDebug    = 3;
$mail->isSMTP();
$mail->Host       = 'smtp.yourserver.topleveldomain'; 
$mail->Port       = yourportnumber;
$mail->SMTPSecure = 'yourprotocol';
$mail->SMTPAuth   = true;
$mail->Username   = 'SmtpUsername';
$mail->Password   = 'SmtpPassword';
$mail->setFrom(     'sender@domain.tld', 'Sender Name')
$mail->addReplyTo(  $email_from, '{clean_string($first_name)}{clean_string($last_name)}');
//repeat the next line for multiple  recipients.
$mail->addAddress('user@domain.tld', 'Recipient Name');
$mail->Subject = 'mail subject';
$mail->Body = $email_message;
我还使用了不同的变量将body参数传递给:

    $mail->AltBody = '{$email_message}';
现在是什么

    $mail->Body = $email_message;

此外,来自验证程序的重定向阻止了所有错误代码的显示。注释Captcha2 php代码使发现它们变得容易。

我的问题是初始化“$mail=new PHPmailer;”后参数传递给PHPmailer的顺序

应该是:

$mail = new PHPMailer;
$mail->SMTPDebug    = 3;
$mail->isSMTP();
$mail->Host       = 'smtp.yourserver.topleveldomain'; 
$mail->Port       = yourportnumber;
$mail->SMTPSecure = 'yourprotocol';
$mail->SMTPAuth   = true;
$mail->Username   = 'SmtpUsername';
$mail->Password   = 'SmtpPassword';
$mail->setFrom(     'sender@domain.tld', 'Sender Name')
$mail->addReplyTo(  $email_from, '{clean_string($first_name)}{clean_string($last_name)}');
//repeat the next line for multiple  recipients.
$mail->addAddress('user@domain.tld', 'Recipient Name');
$mail->Subject = 'mail subject';
$mail->Body = $email_message;
我还使用了不同的变量将body参数传递给:

    $mail->AltBody = '{$email_message}';
现在是什么

    $mail->Body = $email_message;

此外,来自验证程序的重定向阻止了所有错误代码的显示。注释Captcha2 php代码使发现它们变得容易。

“脚本没有返回错误”-您对此有多确定?您只是在使用
$mail->SMTPDebug=3哪些测试针对SMTP连接,但在PHP方面呢?这个表格怎么样?你确定所有的POST数组都进行了评估?其中还包括
if(isset($\u POST['submit'])
。感谢您的回复,我已经在本地运行了脚本,没有收到任何错误。也很抱歉没有包括要点url,因为我已经做了,但忘了包括它。出于缩写的考虑,我决定在代码块中使用php,对于html,我想参考以下链接:如果添加
$mail->ErrorInfo将打印邮件错误。您无法查看错误,因为您正在重定向到contact.php<代码>如果(!$mail->send()){echo'邮件无法发送。;;echo'邮件错误:'.$mail->ErrorInfo;//标题('location:contact.php?CaptchaPass=True');}
只需对标题行进行注释,如图所示,然后让我查看know@RiggsFolly我不再发布错误报告的东西了。我很高兴你这么做了,但我只是发布了一个通用的“检查错误”。“脚本没有返回错误”-你对此有多确定?您只是在使用
$mail->SMTPDebug=3哪些测试针对SMTP连接,但在PHP方面呢?这个表格怎么样?你确定所有的POST数组都进行了评估?其中还包括
if(isset($\u POST['submit'])
。感谢您的回复,我已经在本地运行了脚本,没有收到任何错误。也很抱歉没有包括要点url,因为我已经做了,但忘了包括它。出于缩写的考虑,我决定在代码块中使用php,对于html,我想参考以下链接:如果添加
$mail->ErrorInfo将打印邮件错误。您无法查看错误,因为您正在重定向到contact.php<代码>如果(!$mail->send()){echo'邮件无法发送。;;echo'邮件错误:'.$mail->ErrorInfo;//标题('location:contact.php?CaptchaPass=True');}
只需对标题行进行注释,如图所示,然后让我查看know@RiggsFolly我不再发布错误报告的东西了。我很高兴你这么做了,但我只是发布了一个通用的“检查错误”。