1

I'm trying to add some mark-up to an email that's generated by a PHP script, but it doesn't appear to be parsing the tags as they are are visible in the email along with the content. Any help would be really appreciated. Thanks!

Script:

<?php

$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$message = Trim(stripslashes($_POST['message']));
$emailFrom = $email;
$emailTo = "[email protected]";
$subject = "Subject Line";

// Prepare email body text
$body = "<strong>Name:</strong> $name <br /> Email: $email <br /> Message: $message";

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Send email 
$success = mail($emailTo, $subject, $body, "From: $name <$emailFrom>");

// Redirect to success or error pages
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}

?>

Output:

<strong>Name:</strong> My Name <br /> Email: [email protected] <br /> Message: TEST

2 Answers 2

3

in your code, you don't use $headers

change these lines :

$headers  = "";  
$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name <$emailFrom>" . "\r\n";

// Send email 
$success = mail($emailTo, $subject, $body, $headers);

and if it's not enough to work, I advice you tu use a opensource mailer like phpmailer : http://phpmailer.worxware.com/index.php?pg=examples

Sign up to request clarification or add additional context in comments.

1 Comment

This worked! But presented another issue. Commented on other (same) answer.
1

You are not passing the $header to you mail function. Please add "From: $name <$emailFrom>" to your $header and then pass it to the mail function:

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name <$emailFrom>" . "\r\n";

// Send email 
$success = mail($emailTo, $subject, $body, $header);

2 Comments

I see what you mean. That worked! The tags are now being parsed, but the from name/email is only displaying as "$name".
I'm sorry, I used the wrong type of quotes (single quotes instead of double quotes). I edited my answer. Is it working now?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.