Jump to content

Problem with PHP email content


AdamLewis
Go to solution Solved by jazzman1,

Recommended Posts

My code does everything it is supposed to, but within the body of the email I receive is just "My name is $name.
$from
$email
$message"

Here is the PHP code that I'm working with (obviously I've changed the email address for this purpose):

 

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: Your Website';
    $to = 'example@hotmail.co.uk';
    $subject = 'message.';
    $message = 'My name is $name.
$from
$email
$message';

if ($_POST['submit']) {
    mail($to, $subject, $message);
    $feedback = 'Thank you, your message has been sent.';
}

?>

 

Working with the HTML:

        <p id="feedback"><?php echo $feedback; ?></p>

<form method="post" action="contact.php">
    
    <label for="name">Name</label>
    <input id="name" name="name" placeholder="Type Here">
    
    <label for="email">Email</label>
    <input id="email" name="email" type="email" placeholder="Type Here">

    <label for="message">Message</label>
    <textarea name="message" placeholder="Type Here"></textarea>
    <input id="submit" name="submit" type="submit" value="Submit">
        
</form>

 

Thanks for your help in advance.

Link to comment
Share on other sites

  • Solution

When the php parser encountered a string enclosed in single quotes in the php document, it treats variables and any others spacial symbols like \n,&,|| and so on...as a literal text.In your example above not only the value of $name will be escaped but $from,$email,$message as well.

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.