Good day

I want to write multiple response to my email, I get line 7

Please can anyone help please;

My code

<?php
$to = "info@apps4u.co.za"; 
$subject = "Contact Us"; 
$email = $_REQUEST['email'] ;

$q1 = "Feed back text:\n";
$q1 .= "$_REQUEST['text']\n" ;
$q2 = "Who sent you:";
$q2 .= "$_REQUEST['whosentyou']\n" ;

$name = $_REQUEST['name'] ;
$headers = "From: $name <$email>";
$whosentyou = $_REQUEST['whosentyou'] ;
$message = $q1 . "\n". $q2; 
$sent = mail($to, $subject, $message, $headers) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?>

The error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Domains\apps4u.co.za\wwwroot\ServecisRequest.php on line 7

Thanks

Dani AI

Generated

The parse error on line 7 in 's code is the classic PHP string-parsing problem combined with unvalidated user input. pointed toward the immediate syntax fix; beyond that, the code should also validate and sanitize form fields, avoid using $_REQUEST for form posts, and block header-injection in headers. 's note about using a proper editor is sensible — an editor that shows syntax highlighting and error reporting will catch these quickly.

A safer, minimal pattern to follow (validate, sanitize, build, send) looks like this:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$recipient = 'contact@example.com';
$subject   = 'Website contact';
$name      = isset($_POST['name']) ? trim($_POST['name']) : '';
$email     = isset($_POST['email']) ? trim($_POST['email']) : '';
$bodyText  = isset($_POST['message']) ? trim($_POST['message']) : '';

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    exit('Invalid email address.');
}

$safeName  = preg_replace('/[\r\n]+/', ' ', $name); // prevent header injection
$safeEmail = preg_replace('/[\r\n]+/', '', $email);

$body = "From: $safeName <$safeEmail>\n\n$bodyText";

$headers  = "From: {$safeName} <{$safeEmail}>\r\n";
$headers .= "Reply-To: {$safeEmail}\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

$ok = mail($recipient, $subject, $body, $headers);
if (! $ok) {
    error_log("Mail send failed for $safeEmail");
}
?>

Troubleshooting: enable development error reporting, check the local MTA or SMTP settings in php.ini and server logs (mail() can return true while delivery still fails). For HTML emails add an appropriate Content-Type and only include HTML tags when sending HTML. For stronger reliability and SMTP auth, use a maintained library instead of raw mail().

References: PHP mail() usage (mail() manual), input validation (filter_var()), and consider a library like PHPMailer.

Recommended Answers

All 4 Replies

Member Avatar for Member #380484

PHP does not like array values inside of strings ...
You can do several things here. Replace $q1 .= "$_REQUEST\n" ; with ...

$q1 .= "{$_REQUEST['text']}\n"
// ... or ...
$q1 .= $_REQUEST['text']."\n";

Hope this helps

Thanks I will try this and get back to you.
Thank you

try this it will work

<?php
$to = "info@apps4u.co.za"; 
$subject = "Contact Us"; 
$email = $_REQUEST['email'] ;

$q1 = "Feed back text:\n";
$q1 .= $_REQUEST['text'] ."<br />" ;
$q2 = "Who sent you:";
$q2 .= $_REQUEST['whosentyou']."<br />" ;
$name = $_REQUEST['name'] ;
$headers = "From:". $name ."<".$email.">";
$whosentyou = $_REQUEST['whosentyou'] ;
$message = $q1 . "\n". $q2; 
$sent = mail($to, $subject, $message, $headers) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?>

dear vican


use some good editor like dreamweaver or vs.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.