Hi All,
Having some troubles getting my Mail Headers to work. I can get most of them to work so that the email displays as HTML using the Mime types, but as soon as I add the "from:" email address part, the emails fail to send.
I've tried the script without using the headers, and it sends, and then I've tried the script with one header at a time, and it always fails when I add the From: part, but only if I add the Variable.
I've looked up the function on PHP.net and I'm quite familiar with the mail() function anyway, I just cant understand for the life of me why it wont send using a variable for the From: section.
Now, I'm pretty sure it's to do with the variables... because if I add the section of code straight from php.net the mail will send with the from: headers filled in correctly, using this:
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
Here's the code I'm using, which is basic - but in theory should work...
form.html
<form action="send.php" method="post">
<input type="text" name="email" value="YourMail"><br>
<input type="text" name="subject" value="Subject"><br>
<textarea name="message"></textarea><br>
<input type="submit" name="submit" value="Submit"><BR>
</form>
send.php
<?php
$ownermail = 'phil@phildiggle.co.uk';
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = nl2br($_POST['message']);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
mail($ownermail,$subject,$message,$headers);
?>
If you take the last $headers variable out, the script works. Add in the last headers variable and the script fails. It's probably something simple that I'm over looking, but I can't understand why it wont work using a variable for the email address...
Cheers for looking!