There is a contact form already built in Wordpress Theme.
It's at the bottom of the page nikosis.mzonespace.co.uk
It's works ok, it's sending everything correctly to a good email besides non-english signs. There are just question marks when you want to type signs like ą, ę, ć, ź, ł, ó.
So it looks like this: ?, ?, ?, ?, ?, ?.
How to make it work? I tried hard for a an hour or two but couldn't find a solution.
Here's a contact form's code:
<?php
$st_url = dirname(__FILE__);
if ( preg_match('#wp-content#isU', $st_url) ) {
$path_to_file = explode('wp-content', $st_url);
$path_to_wp = $path_to_file[0];
require_once $path_to_wp .'/wp-load.php';
}
else {
require_once '../../../../../../wp-load.php';
}
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if ( isset($_POST) )
{
$_POST = array_map('trim', $_POST);
$contact_name = stripslashes($_POST['fullname']);
$contact_email = stripslashes($_POST['email']);
$persons_attending = stripslashes($_POST['persons_attending']);
$wedding_ceremony = stripslashes($_POST['wedding_ceremony']);
$regex_email = "/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix";
if ( empty($contact_name) ) {
$halt[] = __('Please enter your name.', 'beau');
}
if ( empty($contact_email) ) {
$halt[] = __('Please enter your email.', 'beau');
}
elseif ( !valid_email($contact_email) ) {
$halt[] = __('Please enter a valid email address.', 'beau');
}
// td
if ( isset($halt) )
{
echo '<div class="st-message error">';
echo '<a href="#" class="close" data-dismiss="alert">×</a>';
echo @implode('<br />', $halt);
echo '</div>';
}
else {
$messages = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr><td valign="top"><b>'. __('Name', 'beau') .'</b></td><td valign="top">' . $contact_name . '</td></tr>
<tr><td valign="top"><b>'. __('Email', 'beau') .'</b></td><td valign="top">' . $contact_email . '</td></tr>
<tr><td valign="top"><b>'. __('Subject', 'beau') .'</b></td><td valign="top">' . $contact_subject . '</td></tr>
<tr><td valign="top"><b>'. __('Message', 'beau') .'</b></td><td valign="top"></td></tr>
<tr><td valign="top" colspan="2"><td valign="top">' . $contact_message . '</td></tr>
</table>
</body>
</html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: " . stripslashes($contact_name) . " <" . $contact_email . ">" . "\r\n";
$headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "\r\n";
$headers .= "Priority: normal" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$body = utf8_decode($messages);
if(!empty($_POST['send_to'])){
$to = $_POST['send_to'];
}else{
$to=of_get_option('contact_email');
}
$subject = __('Contact Email From', 'beau') .': '. $contact_name;
if ( wp_mail( $to, $subject, $body, $headers ) )
{
echo '<div class="st-message success">';
echo '<a href="#" class="close" data-dismiss="alert">×</a>';
echo of_get_option('contact_success', 'Your form has been submitted successfully! Thank you!');
echo '</div>';
}
else
{
echo '<div class="st-message error">';
echo '<a href="#" class="close" data-dismiss="alert">×</a>';
echo 'Something went wrong!';
echo '</div>';
}
}
}
This is my code, I added some modifications. This one I got last time was a root file.
Still, it doesn't work:
<?php
$st_url = dirname(__FILE__);
if ( preg_match('#wp-content#isU', $st_url) ) {
$path_to_file = explode('wp-content', $st_url);
$path_to_wp = $path_to_file[0];
require_once $path_to_wp .'/wp-load.php';
}
else {
require_once '../../../../../../wp-load.php';
}
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if ( isset($_POST) )
{
$_POST = array_map('trim', $_POST);
$contact_name = stripslashes($_POST['fullname']);
$contact_email = stripslashes($_POST['email']);
$persons_attending = stripslashes($_POST['persons_attending']);
$wedding_ceremony = stripslashes($_POST['wedding_ceremony']);
$regex_email = "/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix";
if ( empty($contact_name) ) {
$halt[] = __('Please enter your name.', 'beau');
}
if ( empty($contact_email) ) {
$halt[] = __('Please enter your email.', 'beau');
}
elseif ( !valid_email($contact_email) ) {
$halt[] = __('Please enter a valid email address.', 'beau');
}
// td
if ( isset($halt) )
{
echo '<div class="st-message error">';
echo '<a href="#" class="close" data-dismiss="alert">×</a>';
echo @implode('<br />', $halt);
echo '</div>';
}
else {
$messages = '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="Content-Type" content="text/html charset=UTF-8" /></head>
<body>
<table>
<tr><td valign="top"><b>'. __('Name', 'beau') .'</b></td><td valign="top">' . $contact_name . '</td></tr>
<tr><td valign="top"><b>'. __('Email', 'beau') .'</b></td><td valign="top">' . $contact_email . '</td></tr>
<tr><td valign="top"><b>'. __('Subject', 'beau') .'</b></td><td valign="top">' . $persons_attending . '</td></tr>
<tr><td valign="top"><b>'. __('Message', 'beau') .'</b></td><td valign="top"></td></tr>
<tr><td valign="top" colspan="2"><td valign="top">' . $wedding_ceremony . '</td></tr>
</table>
</body>
</html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= "From: " . stripslashes($contact_name) . " <" . $contact_email . ">" . "\r\n";
$headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "\r\n";
$headers .= "Priority: normal" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$body = utf8_decode($messages);
if(!empty($_POST['send_to'])){
$to = $_POST['send_to'];
}else{
$to=of_get_option('contact_email');
}
$subject = __('Contact Email From', 'beau') .': '. $contact_name;
if ( wp_mail( $to, $subject, $body, $headers ) )
{
echo '<div class="st-message success">';
echo '<a href="#" class="close" data-dismiss="alert">×</a>';
echo of_get_option('contact_success', 'Your form has been submitted successfully! Thank you!');
echo '</div>';
}
else
{
echo '<div class="st-message error">';
echo '<a href="#" class="close" data-dismiss="alert">×</a>';
echo 'Something went wrong!';
echo '</div>';
}
}
}