In your mail function, you reference the following: $body[$headers]
$body is a string, as is $headers. You are attempting to index $body with an index of $headers. This doesn’t really make logical sense, but isn’t invalid. What PHP will attempt to do with this code is convert the string $headers into a number. This will result in 0.
To see how PHP converts strings into numbers, see: http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion]
Since $headers converts into 0, this results in indexing your $body string at the first character (which is <).
If you were to look at the manual entry (http://php.net/manual/en/function.mail.php) for the PHP mail() function, you would see that the argument list is formatted as follows:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Note that when the manual uses the square brackets, it is not saying you should surround those parameters in square brackets (like what you did in your code), but rather it signifies that those parameters are optional. Your headers go after the message parameter (which in your code is $body) and you separate them with a comma much like any other parameter… Thus, your mail statement should be as follows:
[php]
$success = mail($webMaster,$emailSubject,$body,$headers);
[/php]
Also, the following may be incorrect:
[php]
$headers = “From:$input_email\r\n”;
$headers = “content-type/text\r\n”;
[/php]
You are reassigning your $headers variable, and it seems like you mean to concatenate here. Perhaps that should be
[php]
$headers = “From:$input_email\r\n”;
$headers .= “content-type/text\r\n”;// .= is the compound concatenation operator.
//its equivalent to $headers = $headers . “content-type/text\r\n”;
[/php]"
Also, you have HTML in your email body, but your headers indicate that the content in your email should be rendered as plain text (thanks to the “content-type/text\r\n” directive in your header string). If you want your HTML to be rendered correctly, you want to tell the email client, that the email is being sent to, to interpret the email content as HTML. That requires the following header:
"Content-type: text/html\r\n";
thus, your $headers assignments become:
[php]
$headers = “From:$input_email\r\n”;
$headers = “Content-type: text/html\r\n”;
[/php]
btw your content-type directive (this: “content-type/text\r\n”) was malformed, and this is probably the reason that your email did not send correctly.
Now, the end product of your script after the fixes above may look like this:
<?php
/* Subject and Email Variables */
$emailSubject = 'Refill Request';
$webMaster = '[email protected]';
/* Gathering Data Variables */
$input_fn = $_POST['firstname'];
$input_ln = $_POST['lastname'];
$input_dob = $_POST['dob'];
$input_email = $_POST['email'];
$input_phone = $_POST['phone'];
$input_rx1 = $_POST['rx1'];
$input_rx2 = $_POST['rx2'];
$input_rx3 = $_POST['rx3'];
$input_rx4 = $_POST['rx4'];
$input_rx5 = $_POST['rx5'];
$input_rx6 = $_POST['rx6'];
$textarea = $_POST['textarea'];
$body = <<<EOD
<br><hr><br>
Firstname: $firstname <br>;
Lastname: $lastname <br>;
DOB: $dob <br>;
Email: $email <br>;
Phone: $phone <br>;
RX1: $rx1 <br>;
RX2: $rx2 <br>;
RX3: $rx3 <br>;
RX4: $rx4 <br>;
RX5: $rx5 <br>;
RX6: $rx6 <br>;
Comments: $textarea <br>;
EOD;
$headers = "From:$input_email\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster,$emailSubject,$body,$headers);
if (!$success){ echo "Email could not be sent. Please refresh and try again"; }
else { "Successfully sent email. Thank you for the response!"; }
?>
I added that last if-else statement just so you can see if the email was sent or not.
Hope this helps