[quote]Thanks for your reply, but as I’m not a PHP developer, I’m only cutting and pasting from existing code I’ve found online.
I wish I could run a bug check on this code somehow!
I’m still not able to receive HTML emails, and my code is now:[/quote]
Copy and pasting code when you don’t know what it does will lead to trouble a lot of times. In your case though you don’t have to be a developer you just have to apply some problem solving skills.
You already know that in sending a message, you need a set of recipients, a subject, and a message, right? So $to, $subject and $message should be slam dunks…
But you know you need to add some headers that indicate the message is HTML. You already know what those headers are. But how do we use those headers when sending the message? Let’s see if we can do that with the mail() function. The documentation says:
[code]bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). [/code]Sweet, we can specify additional headers! OK so we got our research done. Let’s apply what we’ve learned:
We need a $to
We need a $subject
We need a $message
We need a $additional_headers
And then we call
mail($to, $subject, $message, $additional_headers);
So, what do we have for our parameters so far?
$headers = “MIME-Version: 1.0rn”;
$headers .= “Content-type: text/html; charset=iso-8859-1rn”;
$to = "email@example.com";
$msg = “$name\n\n”;
$msg .= “$message\n\n”;
Damn. We’re missing $subject. Let’s try again, renaming the variables though so I understand what the documentation says they are for… and duh I want to specify a reply-to address, almost forgot. And yeah, I don’t want someone using this to send spam from my site, either. [code]# We need to sanitize $email before using it in a message header
$replyto = preg_replace(’/[^\x20-\x7E]/’, ‘’, $email);
$to = "firstname.lastname@example.org";
$subject = “Message From: Online client”
$message = “$name\n\n”;
$message .= “$message\n\n”;
$additional_headers = “MIME-Version: 1.0\n”;
$additional_headers .= “Content-type: text/html; charset=iso-8859-1\n”;
$additional_headers .= “Reply-to: $replyto\n”;
OK now that I finally got the parameters ready and look at that they are in order I need for
the call to mail() too!
mail($to, $subject, $message, $additional_headers);[/code]Sigh, if only all of “PHP developing” was as easy as reading a little and filling in the blanks
Customer since 2000 openvein.org