styler Posted January 13, 2010 Share Posted January 13, 2010 Hi, This should be simple but..as a newbie: I have created a simple php script for a contact form. I want to include dynamic content in the $message field, although it seems to only allow normal text: This works: $message = ("Hi,</br></br>Your friend wanted to share our website, http://www.example.com with you. We hope you find it interesting!.</br></br>Kind Regards</br>example.com"); This doesn't: $message = ("Hi,</br></br> ".$name"wanted to share our website, http://www.example.com with you. We hope you find it interesting!.</br></br>Kind Regards</br>Example.com"); Full code: 1. <?php 2. if(isset($_POST['submit'])) { 3. 4. $email = $_POST['email']; 5. $name = $_POST['name']; 6. 7. $to = $email; 8. $subject = ("recommendation from: ".$name); 9. $message = ("Hi,</br></br> ".$name"wanted to share our website, http://www.example.com with you. We hope you find it interesting!.</br></br>Kind Regards</br>example.com"); 10. $header = ("From:Recommendation from: ".$name); 11. 12. if(mail($to,$subject,$message,$header)) { 13. $result = "Many thanks for recommending us to a friend"; 14. } else { 15. $result = "<h3>Error sending your message.</h3> 16. Sorry, an error occured sending.<br />Please try again later or contact us direct to be added to the mailing list"; 17. }} 18. ?> Thanks for your help! Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 13, 2010 Share Posted January 13, 2010 Remove those brackets when you assign variables: $subject = ("recommendation from: ".$name); Should be: $subject = "recommendation from: " . $name; Also note that you can include strings within " ", so you could just do: $subject = "recommendation from $name"; Try this with your $message, but if you wanted to end quotes and begin again you would need to do this: $message = "Hi,</br></br> " . $name . "wanted to share our website, http://www.example.com with you. We hope you find it interesting!.</br></br>Kind Regards</br>Example.com"; Quote Link to comment Share on other sites More sharing options...
styler Posted January 13, 2010 Author Share Posted January 13, 2010 That's great - thanks. One other thing though..my html <br/> tags are showing as text in the email, rather than breaks - any reason why? Quote Link to comment Share on other sites More sharing options...
mattal999 Posted January 13, 2010 Share Posted January 13, 2010 Well you have two options. Set the MIME type to HTML (Google that) or you could just use \n instead of <br /> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.