Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Wrapping Up The Project Sending The Contact Form Email

Andraž Lazi?
Andraž Lazi?
3,130 Points

Strange characters in email. How to correct that in this particular example?

When the form is submited the email subject and also the content have strange characters (like: PovpraÅ¡evanje | ÄŒofot Ä ikor). I am not using English. How to fix traht problem?

2 Answers

Because its not english, you can try to parse it through some function like =>

utf8_decode(' strings ')        htmlentities(' stings ')         html_entity_decode('  string' )      

I am not sure what you are trying to do, but hopefully may work out for you

Andraž Lazi?
Andraž Lazi?
3,130 Points

I am aware of that but where to put that? Is it isomwhere inside that code that is below from the contact.php at Shirts4Mike?

$email_body = ""; $email_body = $email_body . "Name: " . $name . "<br>"; $email_body = $email_body . "Email: " . $email . "<br>"; $email_body = $email_body . "Message: " . $message;

$mail->SetFrom($email, $name);
$address = "orders@shirts4mike.com";
$mail->AddAddress($address, "Shirts 4 Mike");
$mail->Subject    = "Shirts 4 Mike Contact Form Submission | " . $name;

Or do I need to include it somewhere else?

Maybe somewhere you mention that has the parsing error, was it subject and contents? I would try something like this.

$subject = "Shirts 4 Mike Contact Form Submisstion |" . $name;
$mail-> Subject = utf8_decode($subject);

$mail-> MsgHTML(utf8_decode($email_body));

That should parse any strange characters in your email. I hope that works.

Andraž Lazi?
Andraž Lazi?
3,130 Points

I just implemented that but it didn't work -.-. Thanks anyway.