Hey so this is my first ever PHP contact form. Everything is working fine and I am receiving the emails, however the content of the email shows as "0".
My PHP code is:
$content = $_POST['name'] + $_POST['message'];
With name being the name of the form element (person's name), and message being the name of the message element. Both are displaying in the PHP array when I do print_r.
It's the email content that is the issue! I followed a Udemy tutorial on how to do this and have double checked everything. Can anyone help me??
Thanks!!!!
Judging by your submitted code, it looks like you're attempting to take the form submitter's name and their message and combine it into a single string that will be placed within the body of your email.
The primary issue that stands out is how you're attempting to concatenate (combine) the strings. In PHP, the concatination operation is the period ("."). With your current code, it's attempting to add the two strings like numbers, which is why you're encountering that 0 in your email body.
Let's take your current code, and apply that fix:
$content = $_POST['name'] . $_POST['message'];
Secondly, let's take a look at the actual output of your $content variable. Should I submit the name "Jon" and my message be "Hello, friends!" with your code as it is now, we would end up with:
JonHello,Friends!
To remedy this, let's add in a colon and a space to denote that the user is saying this message:
$content = $_POST['name'] . ': ' . $_POST['message'];
Now, should we output the $content variable, we'll see:
Jon: Hello, Friends!
Bear in mind, our addition of the colon and space could be substituted for any other string.
For instance, we could modify our concatenation only slightly to add a bit of flavor to our text and have the user "say" her/his name:
$content = $_POST['name'] . 'says: "' . $_POST['message'] .'"';
This code, when output, would produce:
Jon says: "Hello, friends!"
I hope that helps, Grand. Let me know if you have any further questions.