Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Error

Featured Replies

on the contact form,

 

syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on line 20

 

<?php
 $email = $_REQUEST['phone'] ;
 $message = $_REQUEST['enquiry'] ;
 $name = $_REQUEST['name'];

if (!isset($_REQUEST['phone'])) {
   header( "Location: http://www.garethgillman.co.uk/contact.php" );
 }
 elseif (empty($phone) || empty($enquiry) || empty($name)) {

 header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
   header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
   header( "Cache-Control: no-cache, must-revalidate" );
   header( "Pragma: no-cache" );

}
 else {
   mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name:" .$name. "<br />"
     "Contact No:" .$phone. "<br />"
     "Enquiry:" .$enquiry. );
   header( "Location: index.php" );
 }
?>

 

It's within the mail section at the bottom, I have no idea how to solve PHP errors

You're not concatenating the strings properly - you're forgetting to add a . between lines, and you have an extra . before the closing ). You should have either:

 

mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name:" .$name. "<br />" .
     "Contact No:" .$phone. "<br />" .
     "Enquiry:" .$enquiry );

(note the extra . after the "<br />" on each line), or reduce the number of concatenations required with:

 

mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name:" .$name.
     "<br />Contact No:" .$phone.
     "<br />Enquiry:" .$enquiry );

You can also insert variables directly into the strings in PHP, without doing explicit concatenation, like this:

 

mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name: $name<br />Contact No: $phone<br />Enquiry: $enquiry");

 

Hope that helps!

  • Author

You're not concatenating the strings properly - you're forgetting to add a . between lines, and you have an extra . before the closing ). You should have either:

 

mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name:" .$name. "<br />" .
     "Contact No:" .$phone. "<br />" .
     "Enquiry:" .$enquiry );

(note the extra . after the "<br />" on each line), or reduce the number of concatenations required with:

 

mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name:" .$name.
     "<br />Contact No:" .$phone.
     "<br />Enquiry:" .$enquiry );

You can also insert variables directly into the strings in PHP, without doing explicit concatenation, like this:

 

mail( "info@sglettings.co.uk", "Contact Form Results",
     "Name: $name<br />Contact No: $phone<br />Enquiry: $enquiry");

 

Hope that helps!

 

 

Worked a little, but now just get a white page .... The same contact form works fine on another site I did

Worked a little, but now just get a white page .... The same contact form works fine on another site I did

 

Hi,

 

I have totally rewritten your code and tested it.

 


<?php
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

$message = $_REQUEST["enquiry"];
$name = $_REQUEST["name"];
$phone = $_REQUEST["phone"];
$email = $_REQUEST["email"]; // optional

$contents = <<<EOD
Name: $name
Phone: $phone
Message: $message
EOD;


if (empty($phone) || empty($message) || empty($name)) {
	header("Location: http://www.garethgillman.co.uk/contact.php");
}


else {
	if(!isset($email)) {
	$email = "webform@sglettings.co.uk";
	}
	$headers = "From: $name <$email>\r\n" .
	"Reply-To: $email\r\n";
	if(mail("info@sglettings.co.uk", "Contact Form Results", $contents, $headers)) {
	header("Location: /sent.php");
	exit;
	}

	else {
	header("Location: /error.php");
	exit;
	}
}
?>

 

Any issues let me know,

 

Kyle

Edited by Kyle Hudson MCP CCNA CIW

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.