Jump to content

simple contact form problem


styler

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/188310-simple-contact-form-problem/
Share on other sites

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";

 

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.