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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.