Chandan Jha
Chandan Jha

Reputation: 45

Getting error after email send

I have created contact form to make contact user to admin. I use PHP Mailer to sent mail to admin email id. It work, i also got email but when i submit form give alert Form Submitted successfully then i face some error. I don't understand what happen wrong. Please help me. I provide below contact form and error.

Here's my backend_contact.php page coding.

<?php       
    include 'phpmailer/PHPMailerAutoload.php';

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

        $name = $_POST['name'];
        $email = $_POST['email'];
        $msg = $_POST['message'];

        $full_message='<table width="650" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">    
        <tr>
            <td width="584" bgcolor="#FFFFFF"><span class="style3">Parekh Website Contact Form</span></td>
        </tr>
        <tr>
            <td height="45" valign="middle" bgcolor="#FFFFFF">
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr>
                        <td width="59%">
                            <p class="style3"><strong>Name :</strong>'.$name.'</p>
                            <p class="style3"><strong>Email ID: </strong>  '.$email.'</p>                   
                            <p class="style3"><strong>Message:</strong> '.$msg.'</p> 
                        </td>
                    </tr>
                </table>
            </td>
        </tr>     

        <tr>
            <td height="68" bgcolor="#FFFFFF" >
                <p>With warm regards, </p>
                <p>Administrator <br />
                    Parekh</p></td>
            </tr>
        </table>';

        if(empty($name)){
            echo "<script type='text/javascript'>
                alert('Please Enter Your Name.')
                window.location = '../contact.php';
            </script>";
        }
        elseif(empty($email)){          
            echo "<script type='text/javascript'>
                alert('Please Enter Your Email Id.')
                window.location = '../contact.php';
            </script>";
        }
        elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)){
            echo "<script type='text/javascript'>
                alert('Please Enter Valid Email.')
                window.location = '../contact.php';
            </script>";
        }
        elseif(empty($msg)){
            echo "<script type='text/javascript'>
                alert('Please Enter Your Message.')
                window.location = '../contact.php';
            </script>";
        }
        else{
            $mail = new PHPMailer;
            $mail->isSMTP();
            $mail->SMTPDebug = 2;
            $mail->Debugoutput = 'html';
            $mail->Host = 'smtp.sendgrid.net';
            $mail->Port = 587;
            $mail->SMTPSecure = 'tls';
            $mail->SMTPAuth = true;
            $mail->Username = "xxxx.in";
            $mail->Password = "xxxx";
            $mail->setFrom('[email protected]','xxxx');
            $mail->addAddress('[email protected]', 'xxxx');            
            $mail->Subject = 'Website Contact Form';
            $mail->msgHTML($full_message);          
            $mail->AltBody = 'Website Contact Form';            
            if ($mail->send()){
                echo "<script>
                        alert('Form Submitted successfully.');
                        window.location.href='../contact.php';
                    </script>";
            }
        }   
    }   
?>

And, here's face error after form submitted.

SERVER -> CLIENT: 220 SG ESMTP service ready at ismtpd0008p1hnd1.sendgrid.net
CLIENT -> SERVER: EHLO xxx.in
SERVER -> CLIENT: 250-smtp.sendgrid.net250-8BITMIME250-PIPELINING250-SIZE 31457280250-STARTTLS250-AUTH PLAIN LOGIN250 AUTH=PLAIN LOGIN
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 Begin TLS negotiation now
CLIENT -> SERVER: EHLO xxx.in
SERVER -> CLIENT: 250-smtp.sendgrid.net250-8BITMIME250-PIPELINING250-SIZE 31457280250-STARTTLS250-AUTH PLAIN LOGIN250 AUTH=PLAIN LOGIN
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: cGlzcGwuaW4=
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: UEBzc3cwcmRwaXM=
SERVER -> CLIENT: 235 Authentication successful
CLIENT -> SERVER: MAIL FROM:<[email protected]>
SERVER -> CLIENT: 250 Sender address accepted
CLIENT -> SERVER: RCPT TO:<[email protected]>
SERVER -> CLIENT: 250 Recipient address accepted
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Continue
CLIENT -> SERVER: Date: Wed, 30 May 2018 11:03:19 +0530
CLIENT -> SERVER: To: xxxx <[email protected]>
CLIENT -> SERVER: From: xxxx <[email protected]>
CLIENT -> SERVER: Subject: Website Contact Form
CLIENT -> SERVER: Message-ID: <[email protected]>
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.13 (https://github.com/PHPMailer/PHPMailer)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_6de67638bea8977cdb1aacaadc8d90d4"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER: 
CLIENT -> SERVER: This is a multi-part message in MIME format.
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_6de67638bea8977cdb1aacaadc8d90d4
CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
CLIENT -> SERVER: 
CLIENT -> SERVER: Website Contact Form
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_6de67638bea8977cdb1aacaadc8d90d4
CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
CLIENT -> SERVER: 
CLIENT -> SERVER: <table width="650" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">   
CLIENT -> SERVER: <tr>
CLIENT -> SERVER: <td width="584" bgcolor="#FFFFFF"><span class="style3">Parekh Website Contact Form</span></td>
CLIENT -> SERVER: </tr>
CLIENT -> SERVER: <tr>
CLIENT -> SERVER: <td height="45" valign="middle" bgcolor="#FFFFFF">
CLIENT -> SERVER: <table border="0" cellspacing="0" cellpadding="0" width="100%">
CLIENT -> SERVER: <tr>
CLIENT -> SERVER: <td width="59%">
CLIENT -> SERVER: <p class="style3"><strong>Name :</strong>xxxx</p>
CLIENT -> SERVER: <p class="style3"><strong>Email ID: </strong> [email protected]</p> 
CLIENT -> SERVER: <p class="style3"><strong>Message:</strong> hii test </p> 
CLIENT -> SERVER: </td>
CLIENT -> SERVER: </tr>
CLIENT -> SERVER: </table>
CLIENT -> SERVER: </td>
CLIENT -> SERVER: </tr> 
CLIENT -> SERVER: 
CLIENT -> SERVER: <tr>
CLIENT -> SERVER: <td height="68" bgcolor="#FFFFFF" >
CLIENT -> SERVER: <p>With warm regards, </p>
CLIENT -> SERVER: <p>Administrator <br />
CLIENT -> SERVER: xxxxxx</p></td>
CLIENT -> SERVER: </tr>
CLIENT -> SERVER: </table>
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_6de67638bea8977cdb1aacaadc8d90d4--
CLIENT -> SERVER: 
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 Ok: queued as -ZsWIWQ7SXeYJz-SHpzbkg
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 See you later

Upvotes: 3

Views: 77

Answers (2)

Gautam Rai
Gautam Rai

Reputation: 2505

There is no any error, that is all the Mailer Debug code, since you have set it as

$mail->SMTPDebug = 2;

you should just set the Mailer debug off, so no debug code will be displayed.

use below code.

$mail->SMTPDebug = 0

Upvotes: 1

Ray A
Ray A

Reputation: 1341

try to replace window.location.href with window.location other than that, I don't see any problem, also turn the phpmailer debug off.

Upvotes: 0

Related Questions