Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.