Hi,

Below code gives me this error: "syntax error, unexpected" in line 5

<?php
$to = "safiullah12@hotmail.com";
$subject = "test fname, email,phone,nn";
$Sender = $_POST["email"];
$message = Name: echo $_POST["fname"] . "\r\n". ///////////////////////line 5
Email Address: <?php echo $_POST["email"] . ?> "\r\n".
Phone No: echo $_POST["phone"] . "\r\n" ;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$Sender. "\r\n".
'X-Mailer: PHP/' . phpversion();

mail($to,$subject,$message);
?>


pls advise.
Thx.

i am trying to get a output as below:

Name: abc
Email Address: sdfslkj@ldskfj.com
Phone No: 11111111


Thanks again.

Hi,

Below code gives me this error: "syntax error, unexpected" in line 5

<?php
$to = "safiullah12@hotmail.com";
$subject = "test fname, email,phone,nn";
$Sender = $_POST["email"];
$message = Name: echo $_POST["fname"] . "\r\n". ///////////////////////line 5
Email Address: <?php echo $_POST["email"] . ?> "\r\n".
Phone No: echo $_POST["phone"] . "\r\n" ;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$Sender. "\r\n".
'X-Mailer: PHP/' . phpversion();

mail($to,$subject,$message);
?>


pls advise.
Thx.

I can't say for sure, but I believe that you need to use single quotes inside the instead of the double quotes.

Your code is a syntactical nightmare.
Strings in PHP have to be enclosed in single or double quotes. ($message = Name)
You cannot open a <?php tag inside an already opened one.
A tip: do not mix HTML and PHP code. Write code like yours this as pure PHP without ever closing the PHP bracket.

Hello,

This might work:

<?php 
$to = "safiullah12@hotmail.com";
$subject = "test fname, email,phone,nn";
$Sender = $_POST["email"];
$message = " Name: ".$_POST['fname']."\r\n <br /> Email Address: ".$_POST['email']."\r\n <br /> Phone No: ".$_POST["phone"]."\r\n";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0 \r\n Content-type:text/html;charset=iso-8859-1 \r\n From: ".$Sender."\r\n Reply-To: ".

mail($to,$subject,$message,$headers);
?>

I added <br/> because if you're sending as html you will need it.

Calum

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.