How to display name when message was sent ?

I have created the simple contact form and doing some tweak. My question whenever the visitor sent the message, the line should be display “Thank you $name your form has been submitted”. How can i write this on echo, I am doing this, but it was not taken. Here is my PHP code

[code]<?php

if (isset($_POST[‘contact_name’]) && isset($_POST[‘contact_email’]) && isset($_POST[‘contact_time’]) && isset($_POST[‘contact_text’])) {
$contact_name = $_POST[‘contact_name’];
$contact_email = $_POST[‘contact_email’];
$contact_time = $_POST[‘contact_time’];
$contact_text = $_POST[‘contact_text’];

	if (!empty($contact_name) && !empty($contact_email) && !empty($contact_time) && !empty($contact_text)) {
		$to = '[email protected]';
		$subject = 'Custom Contact Form';
		$body = $contact_name."\n".$contact_time."\n".$contact_text;
		$headers ='From: '.$contact_email;
		
		if (mail($to, $subject, $body, $headers)) {
			echo 'Your form has been submitted. We\'ll contact you shortly.';
			} else {
			echo 'There was an error';
		}
		
	}else {
		echo 'All fields are required.';
	}

}

?>[/code]

$name should be $contact_name and it should be placed on line 18 of the script you posted below.

Red :wink:

Change

echo 'Your form has been submitted. We\'ll contact you shortly.

to

echo 'Thank you $contact_name your form has been submitted.'

almost correct…

In php if you want to echo/print a variable that is wrapped inside quotes, they need to be double quotes " not single ’

so change the line from this:
[php]echo ‘Thank you $contact_name your form has been submitted.’[/php]

to this:
[php]echo “Thank you $contact_name your form has been submitted.”[/php]

or this:
[php]echo ‘Thank you ’ . $contact_name . ’ your form has been submitted.’[/php]

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service