Click here to Skip to main content
15,446,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a problem, want to send an email with php everything is send fine with this code
PHP
<?php
	$mail = $_POST['mail'];
	$name = $_POST['name'];
	$subject = $_POST['subject'];
	$text = $_POST['text'];
	
 $to = "filippos8@otenet.gr";
 
$message =" You received  a mail from ".$mail;
 $message .=" Text of the message : ".$text;
 if(mail($to, $subject,$message)){
	echo "mail successful send";
} 
else{ 
	echo "there's some errors to send the mail, verify your server options";
}
?>

but I want to send the variable $name text too in the message, how can I add this variable to $message?
this code sends only the $name and the text $message
PHP
<?php
	$mail = $_POST['mail'];
	$name = $_POST['name'];
	$subject = $_POST['subject'];
	$text = $_POST['text'];
	
 $to = "filippos8@otenet.gr";
 
$message =" You received  a mail from ".$mail;
$message =" You received  a mail from ".$name;
 $message .=" Text of the message : ".$text;
  if(mail($to, $subject,$message)){
	echo "mail successful send";
} 
else{ 
	echo "there's some errors to send the mail, verify your server options";
}
?>
, the subject both cases send correctly. I am a newbie in php.

Thank you
Kyriakos
Posted
Updated 26-Aug-20 17:45pm

 
Share this answer
 
It's pretty easy:
PHP
$message =" You received  a mail from ".$mail;
$message =" You received  a mail from ".$name;
 $message .=" Text of the message : ".$text;
Add the concatenation operator to trhe second line, like you have in the third:
PHP
$message =" You received  a mail from ".$mail;
$message .=" You received  a mail from ".$name;
$message .=" Text of the message : ".$text;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900