Jump to content

Email Script Problem.


theboxjellyfish

Recommended Posts

I have a problem with a script I wrote for handling emails. Here is the code:

<?php$msg = "<p><strong>E-Mail:</strong> $_POST[email]</p>";$msg .= "<p><strong>Name:</strong> $_POST[name]</p>";$msg .= "<p><strong>Contact Number:</strong> $_POST[contact]</p>";$msg .= "<p><strong>Enquiry:</strong> $_POST[textarea]</p>";$recipient = "****@********.co.uk";$subject = "Enquiry from *********.co.uk";$mailheaders = "MIME-Version: 1.0\r\n";$mailheaders .= "Content-type: text/html; charset=ISO-8859-1\r\n";$mailheaders .= "From: ********** Enquiry Form <*****@********.co.uk> \n";$mailheaders .= "Reply-To: $_POST[email]";mail($recipient, $subject, $msg, $mailheaders);?>

Note: I have censored the email address and such to protect privacy.The problem I’m having is that when it is sent to my email address the HTML formats the content correctly but when it is sent to the person I’m making the website for's email address the text is not formatted and the HTML tags show up instead. If it helps, they are using Outlook to receive their emails (this is factor that isn’t going to change). Can anyone advise me on what to do to resolve this problem? Thank you in advance for any help.

Link to comment
Share on other sites

You might need the< html> and <body> tags in.take a look here - http://php.net/manual/en/function.mail.phpScroll down a bit and theres an example of sending html email via php.Also a good idea to check user input rather than inserting the $_POST variables straight into the email.Hope that helps.:)

Link to comment
Share on other sites

I'll look into that, thank you. I'm still a PHP novice and just grasping the basics so far, I shall check for input. If I'm still having problems I'll report back.EDIT: It is still not formatting the text, the HTML still shows up as text.EDIT 2: I have discovered the problem and the solution. Apparently it's something to do with \r not being parsed as a header or something like that, therefore missing it out has solved the problem.

Link to comment
Share on other sites

All mail headers should be separated with \r\n, not just \n. In your original code one of the headers ends with just \n, that's probably what was confusing it. If you changed that to \r\n it would probably work both with Outlook and any other client.$mailheaders = "MIME-Version: 1.0\r\n";$mailheaders .= "Content-type: text/html; charset=ISO-8859-1\r\n";$mailheaders .= "From: ********** Enquiry Form <*****@********.co.uk> \n";$mailheaders .= "Reply-To: $_POST";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...