[RESOLVED] Set charset in email through contact form
Hey, I've run into a bump in a project. I'm curently working with German characters, and I use UTF-8 on the main page, but the latin char's don't show up correctly in the emails that get sent. Now if I use ISO-8859-1, the char's show up fine in the email, but are no longer visible on the webpage.. Any ideas for a fix?
I was thinking try to set the charset within the email, but maybe there's a way to do it without that? And if not, how would I go about setting the charset within the code to send to the email?
Thanks in advance.
Re: Set charset in email through contact form
Hi Neato,
I don't know if there is another solution to your problem but here's how to set the character set of an email:
Use the Content-type email header:
Code:
Content-Type: text/plain; charset=iso-8859-1
To set this in an email, you can pass headers to the mail function e.g.
PHP Code:
$headers = "From: [email protected]\r\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
$sent = mail($to, $subject, $body, $headers);
Re: Set charset in email through contact form
So, say I'm using the following string:
Code:
send_email($cf_site_title,$cf_webmaster_email,$email,"[Form Result] $de_email_subject",$sender_info.$email_msg,$de_email_format,$replyto);
I would then add the $headers to the end of that, and we'd be set?
Re: Set charset in email through contact form
The code you posted above is using a 'send_email()' function. This is not a built in or standard function of PHP, it must be one that you have created somewhere so you will have to check the code for that function.
Your function is probably using the standard mail() function to actually send the mail, so you should be able to just add an argument at the end and have it passed as the headers argument in the mail() function.
If you're unsure, post the code for your send_mail() function.
Re: Set charset in email through contact form
It's using the FormXP send mail function, if you're familiar with it.
Code:
function send_result_to_admin_email($de_email_admin,$de_email_format,$de_email_subject,$email_msg,$replyto=""){
global $home_root,$home_url,$array_distance,$array,$cf_local_latitude,$cf_local_longitude,$da_admin_ip,$user_agent,$remote_addr,$time_stamp_now,$cf_site_title,$cf_webmaster_email;
$da_upload_filename=get_global_var(file_attach);
$da_upload_folder=get_global_var(file_upload_folder);
if($de_email_format=="0"){//Text
if($da_upload_filename !="" && $da_upload_folder !=""){
$da_upload_size=number_format(filesize("$home_root/resource/user_upload/$da_upload_folder/$da_upload_filename"));
$show_file_attachment="File Attachment: $home_url/resource/user_upload/$da_upload_folder/$da_upload_filename\nFile size: $da_upload_size bytes";
}
$sender_info="Sender Information:\nIP Address: $remote_addr - Country: $array[ip_country] ($array[ip_country_name])\nCity: $array[ip_city] - Region: $array[ip_region] - Zipcode: $array[ip_zipcode] - Phone Area Code (US Only): $array[ip_areacode]\nLatitude: $array[ip_latitude] - Longitude: $array[ip_longitude]\nDistance: $array_distance[miles] miles ($array_distance[kilometers] km) away from admin IP $da_admin_ip\n\nUser Agent: $user_agent\n\n$show_file_attachment\n\n";
}
else{
if($da_upload_filename !="" && $da_upload_folder !=""){
$da_upload_size=number_format(filesize("$home_root/resource/user_upload/$da_upload_folder/$da_upload_filename"));
$show_file_attachment="File Attachment: <a href=$home_url/resource/user_upload/$da_upload_folder/$da_upload_filename>$home_url/resource/user_upload/$da_upload_folder/$da_upload_filename</a><br>File size: $da_upload_size bytes<br><br>";
}
$sender_info="<b>Sender Information:</b><br>IP Address: <b>$remote_addr</b> - Country: <b>$array[ip_country] ($array[ip_country_name])</b><br>City: <b>$array[ip_city]</b> - Region: <b>$array[ip_region]</b> - Zipcode: <b>$array[ip_zipcode]</b> - Phone Area Code (US Only): <b>$array[ip_areacode]</b><br>Latitude: <b>$array[ip_latitude]</b> - Longitude: <b>$array[ip_longitude]</b><br>Distance: <b>$array_distance[miles] miles ($array_distance[kilometers] km)</b> away from admin IP <b>$da_admin_ip</b><br>User Agent: <b>$user_agent</b><br><br>$show_file_attachment";
}
$array_email=split(",",$de_email_admin);
foreach($array_email as $email){
$email=trim($email);
if(valid_email($email))
send_email($cf_site_title,$cf_webmaster_email,$email,"[Form Result] $de_email_subject",$sender_info.$email_msg,$de_email_format,$replyto);
}
}
Re: Set charset in email through contact form
I am not familer with FormXP, I have had a look to see if I could find the source code but I suppose it must not be a free product.
The function you have posted there, is just a wrapper for the send_mail() function, and I assume send_mail() is just a wrapper for the built in mail() function.
Unless you can find the code for the actual send_mail() function for FormXP, I think you will have to get in touch with their tech support and ask them how to set custom email headers with their software.
The same principal will still apply - just set the Content-type email header.:wave:
Re: Set charset in email through contact form
I found the actual function, which is pretty much the same as what I had posted before. This helps a little, maybe? Hopefully ._.
Code:
function send_email($from_name,$from_email,$to,$email_subject,$email_msg,$format,$replyto=""){
//if(get_global_var(cf_sendmail_using_SMTP) == "0"){
Send_Mail_Att($from_name,$from_email,$to,$email_subject,$email_msg,$format,$replyto);
//}
//else{
// SMTP_Mail($from_name,$from_email,$to,$email_subject,$email_msg);
//}
}
Resolved, I found the issue.. It was sending the wrong charset out through the MIME function =S Thanks for the replies and help though =)
Re: Set charset in email through contact form