php - Getting a whole bunch of server output along with wanted output -
when run php script end page says this:
2015-09-29 22:01:01 server -> client: ....[alot of server stuff] message has been sent. thank contacting us. in touch soon.
i want message has been sent text show reason showing whole connecting smtp ,sending message stuff. code follows:
<?php if(isset($_post['email'])) { $email_subject = "new customer requesting information/appointment"; function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , fix these errors.<br /><br />"; die(); } if(!isset($_post['first_name']) || !isset($_post['last_name']) || !isset($_post['email']) || !isset($_post['telephone']) || !isset($_post['comments'])) { died('we sorry, there appears problem form submitted.'); } $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 $error_message = ""; $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'the email address entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'the first name entered not appear valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'the last name entered not appear valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'the comments entered not appear valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "form details below.\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($first_name)."\n"; $email_message .= "last name: ".clean_string($last_name)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "telephone: ".clean_string($telephone)."\n"; $email_message .= "comments: ".clean_string($comments)."\n"; require("phpmailerautoload.php"); $mail = new phpmailer(); // create new object $mail->issmtp(); // enable smtp $mail->smtpdebug = 2; // debugging: 1 = errors , messages, 2 = messages $mail->smtpauth = true; // authentication enabled $mail->smtpsecure = 'tls'; // secure transfer enabled required gmail $mail->host = 'smtp.gmail.com'; $mail->port = 587; $mail->username = "user@gmail.com"; $mail->password = "password"; $mail->from = "user@gmail.com"; $mail->addaddress("sendto@gmail.com"); $mail->subject = $email_subject; $mail->body = $email_message; $mail->wordwrap = 50; if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error: ' . $mail->errorinfo; } else { echo 'message has been sent.'; } ?> thank contacting us. in touch soon. <?php }?>
i using xampp, apache run php script , have been doing stuff 3 days i'm sure silly mistake/misunderstanding.
you're seeing debug output. set:
$mail->smtpdebug = 0;
to turn off.
Comments
Post a Comment