PHP Mail function not picking up variables from $_POST

the mail() function

Moderators: macek, egami, gesf

MaxAwesome
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Mar 05, 2014 1:43 am

PHP Mail function not picking up variables from $_POST

Postby MaxAwesome » Wed Mar 05, 2014 1:54 am

Hi,

I have started learning PHP which I have used sporadically for the last few months.

I have been writing a mail() script but I am having a weird issue with variables within the script.
If I echo the values that are passed via $_POST the variables come out fine. For example $email simply echo's "test@test.com".

However, when I use this variable within my $message it remains blank upon the sending of the e-mail. I just can't figure out why! Ignore the test@test.co.uk as this is just an example. I also realise this doesn't protect me against attacks but that is something I'm going to read up on next once I have this working.

Code: Select all

<?php
   $name = $_POST['yourname'];
   $phone_number = $_POST['phonenumber'];
   $email = $_POST['emailaddress'];
   
   $to = "test@test.co.uk";
   $subject = "New submission";
   $message =    "Name: $name[0] $name[1]\r\n
            Phone Number: $phone_number[0] $phone_number[1]\r\n
            Your E-mail: $email\r\n
   $additional_headers = "From: $name[0] $name[1] \r\n
    <Reply-To: test@test.co.uk> \r\n
    X-Mailer: PHP/" . phpversion();

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


Thanks for your help guys

theboyholty
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Apr 04, 2011 11:34 am

Re: PHP Mail function not picking up variables from $_POST

Postby theboyholty » Fri Apr 04, 2014 11:33 pm

Hi. I'm no expert but you've not closed your double quotes when declaring your $message or $headers variables.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron