Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Php form problem

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

edsmiths

Established Member
Impact
17
Hi there,

I'm trying to use a php script to send a form through an html page.

I've followed this tutorial: [ame="http://www.youtube.com/watch?v=o4acVCCbJcI"]AJAX Form Submission To Email - YouTube[/ame] and used the author files (php code below).

I've managed to configured the html properly but get always this error:

There was an Invalid JSON:
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/mysite.com/feedback.php:1) in /home/user/public_html/mysite.com/feedback.php on line 43
error due to a parsererror condition.

Is there anything wrong with the code or is something in the hosting configurations?

Beside this example... could you please point me a tutorial with simple jquery/ajax/php script to send a form.

Thanks in advance,
Ed

PHP:
<?php 
sleep(2);
//Sanitize incoming data and store in variable
$name = trim(stripslashes(htmlspecialchars($_POST['name'])));	  		
$email = trim(stripslashes(htmlspecialchars($_POST['email'])));
$message = trim(stripslashes(htmlspecialchars($_POST['message'])));	    
$humancheck = $_POST['humancheck'];
$honeypot = $_POST['honeypot'];

if ($honeypot == 'http://' && empty($humancheck)) {	
		
		//Validate data and return success or error message
		$error_message = '';	
		$reg_exp = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,4}$/";
		
		if (!preg_match($reg_exp, $email)) {
				    
					$error_message .= "<p>A valid email address is required.</p>";			   
		}
		if (empty($name)) {
				   
				    $error_message .= "<p>Please provide your name.</p>";			   
		}			
		if (empty($message)) {
					
					$error_message .= "<p>A message is required.</p>";
		}		
		if (!empty($error_message)) {
					$return['error'] = true;
					$return['msg'] = "<h3>Oops! The request was successful but your form is not filled out correctly.</h3>".$error_message;					
					echo json_encode($return);
					exit();
		} else {
				
	//send to an email
$to = 'myemailaddress.com';
$from = 'validemailinthehost.com';
$headers = 'MIME-Version: 1.0' . '\n';
$headers .= 'From: $from' . '\n';
$subject = 'Contact Form Submission\n';
$body = 'Name: ' .$name . '\n';
$body .= 'Email: ' .$email . '\n';
$body .= 'Message: ' .$message . '\n';

	//send email and return a message to the user
	if(mail($to, $subject, $body, $headers)) {

	$return['error'] = false;
			$return['msg'] = "<p>Thanks for your feedback " .$name .".</p>"; 
			echo json_encode($return);
			
			} else {
	
		$return['error'] = true;
		$return['msg'] = "<h3>Oops! There was a problem sending your email. Please try again.</h3>";	
		echo json_encode($return);
		}
	

	}
	
	} else {
	
	$return['error'] = true;
	$return['msg'] = "<h3>Oops! There was a problem with your submission. Please try again.</h3>";	
	echo json_encode($return);
}
	

?>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Put this on line 2:

PHP:
ob_start();
 
2
Close
Thanks mate,

Rep added.
 
1
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back