unrecognized characters sending email in UTF-8 in other account( non gmail) - php

the issue was making a nice looking html contact form design as well as the issue with accepting the user sent mail via a html table instead of a plain text mail
this is the code i am using this is my first work on php
and it's working fine if i am using the web based mail account (gmail)
though if i move the recipent to another account(to my clients domains-email account)
it is then accepting an unregognized characters not ??????? but something like
זוהי ×¤× ×™×” בקשר לבדיקת מייל × ×•×¡
as i said brefore in gmail through the browser it is perfet though
the language in this case is hebrew as you could see in the code below in the subject or body for example
what is missing in this code so it will be ok not only in gmail web mail ?
<?php
$field_name = $_POST['sender_name'];
$field_telephon = $_POST['sender_telephon'];
$field_email = $_POST['sender_mail'];
$field_Subject = $_POST['sender_Subject'];
$field_message = $_POST['sender_message'];
$StrDivOpen = "<div dir='rtl'>";
$StrDivClose = "</div>";
$StrTableOpen = "<table border='1' style='width:260px; font-family:Arial;'>";
$StrTableClose = "</table>";
$StrTrOpen ="<tr>";
$StrTdOpenHd = "<td style='background-color:#fcf7da; width:100px;'>";
$StrTdOpenCont = "<td style='background-color:#dae3a5; width:130px;'>";
$StrTrClose="</tr>";
$StrTdClose="</td>";
$StrBr = "<br />";
$mail_to = 'v7host#gmail.com';
$subject = 'לקוח HostDns, בשם : '.$field_name." , נושא: ".$field_Subject;
$body_message = $StrDivOpen.$StrTableOpen;
$body_message .= $StrTrOpen.$StrTdOpenHd.'מאת : '.$StrTdClose.$StrTdOpenCont.$field_name.$StrTdClose.$StrTrClose;
$body_message .= $StrTrOpen.$StrTdOpenHd.'טלפון : '.$StrTdClose.$StrTdOpenCont.$field_telephon.$StrTdClose.$StrTrClose;
$body_message .= $StrTrOpen.$StrTdOpenHd.'כתובת מייל : '.$StrTdClose.$StrTdOpenCont.$field_email.$StrTdClose.$StrTrClose;
$body_message .= "<tr><td colspan=2 style='background-color:#1cbfbf;'>תוכן ההודעה : </td></tr><tr><td colspan=2 style='background-color:#81c3b2;'>".$StrBr.$field_message."</td></tr></table></div>";
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thanks for the post. We will contact you soon..');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Sending failed. Please send an email to v7host#gmail.com');
window.location = 'contact.html';
</script>
<?php
}
?>

You need to change your encoding to UTF-8:
Content-type: text/html; charset=utf-8
The current encoding you're using (ISO/IEC 8859-1) cannot handle chars from non-Western languages.

Related

PHP Contact Form to Mail not working

Good day everyone, this is my first time to post here so pls bear with me. I need your help guys, I'm an artist that knows basic html5/css that's why i'm really not good in php.
Anyway I have a project that has a contact form, I just realized that yahoo mail is not working when I fill up the form online, but gmail's are good. Below is my php code. I've been following this PHP Mail() Contact-us form works fine if entering a Gmail sending address, but not with Yahoo but I really can't do it on my own! A brother needs your help. Thank you.
<?php
$field_name = $_POST['cf_name'];
$field_brand = $_POST['cf_brand'];
$field_category = $_POST['cf_category'];
$field_email = $_POST['cf_email'];
$field_facebook = $_POST['cf_facebook'];
$field_instagram = $_POST['cf_instagram'];
$field_number = $_POST['cf_number'];
$field_message = $_POST['cf_message'];
$mail_to = 'dulcetlifestylehub#gmail.com';
$subject = 'DULCET LIFESTYLE - BECOME FAMILY: '.$field_name;
$body_message = 'From Owner: '.$field_name."\n";
$body_message .= 'Brand Name: '.$field_brand."\n";
$body_message .= 'Brand Category: '.$field_category."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Facebook: '.$field_facebook."\n";
$body_message .= 'Instagram: '.$field_instagram."\n";
$body_message .= 'Number: '.$field_number."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'becomefamily.htm';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to dulcetlifestylehub#gmail.com');
window.location = 'becomefamily.htm';
</script>
<?php
}
?>

Php form with radio value and queries message

<!-- PHP CONTACT FORM -->
<?php
$look = $_POST['look'];
$design = $_POST['design'];
$old_website = $_POST['old_website'];
$redesign = $_POST['redesign'];
?>
<?php
$field_name = $_POST['user_name'];
$field_email = $_POST['user_email'];
$field_message = $_POST['user_message'];
$mail_to = 'alzirabarretto#gmail.com';
$subject = 'Queries';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message.');
window.location = '/website_form.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to alzirabarretto#gmail.com');
window.location = '/website_form.html';
</script>
<?php
}
?>
I update the php code. When sending the mail it works fine but i don't understand when I didn't received my mail. I have change the radio value according what you have said. And what about the url which I create the input type? I'm bit little confused how to do in php code.
I think this line is wrong.
$radio = $_POST['look' , 'design', 'old_website' , 'redesign'];
Try capturing them separately like this,
$look = $_POST['look'];
$design = $_POST['design'];
$old_website = $_POST['old_website'];
$redesign = $_POST['redesign'];
And even for radio group LOOK, try changing the corresponding values. Or you will get value as radio_1,radio_2, ...

Why the mail content sent are the raw html codes?

Mail content:
<html><head></head><body><p> Message : 鏽嫌╒杜米土 杯屎</p>Share Link : Press here to enter <br><img src ='http://203.80.1.28/FlippingBook/development/demo/medium/Web081112_P070_medium.jpg' /></body></html>
PHP:
if (isset($_POST["data"])){
$info = explode("&", $_POST["data"]);
$headers = 'MIME-Version: 1.0\r\n';
$headers .= "Content-Type: text/html; charset = \"UTF-8\";\n";
$headers = "From: =?UTF-8?B?" . base64_encode(substr($info[0],strpos($info[0],'=')+1, strlen($info[0]))) . "?=";
$to = substr($info[1],strpos($info[1],'=')+1, strlen($info[1]));
$subject = "=?UTF-8?B?" . base64_encode('日報分享') . "?=";
$message = trim(substr($info[2],strpos($info[2],'=')+1, strlen($info[2])));
$message = '<html><head></head><body><p> Message : '.$message;
$url = substr($info[3],strpos($info[3],'=')+1, strlen($info[3]));
$message = $message. '</p>Share Link : Press here to enter ';
if (isset($info[4])){
$firstImg = substr($info[4],strpos($info[4],'=')+1, strlen($info[4]));
$message = $message."<br><img src ='".$firstImg."' />";
}
if (isset($info[5])){
$secondImg = substr($info[5],strpos($info[5],'=')+1, strlen($info[5]));
$message = $message."<br><img src ='".$secondImg."' />";
}
$message = $message.'</body></html>';
if (mail($to, $subject, $message, $headers))
die ('Mail sent');
else
die ('Fail');
}else{
die ('Fail');
}
I am writing a simple program to send email. However, my mail content is not english based so I used utf-8 to encode.
When I changed the encode method, it can not send the processed html code, instead the mail content is the raw html code shown above, how to fix this problem?
If using PEAR lib is not a problem than you can look for Pear Mail-Mime lib to send mail or HTML contents. More details you can get from here - http://pear.php.net/manual/en/package.mail.mail-mime.example.php

My form keeps sending the information to my Junk email

I have a form on my page and the information I submit keeps going to my junk folder within my Hotmail email.
I'm not sure what to do I keep changing the headers but the mail still keeps coming into my junk folder.
The code for the PHP is:
<?php
$boundary = uniqid('np');
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'user#hotmail.co.uk';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: PHP's mail() Function\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$headers .= "Subject: Contact\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
$message .= "This is the text/plain version.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
$message .= "This is the <b>text/html</b> version.";
$message .= "\r\n\r\n--" . $boundary . "--";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. I will contact you shortly.');
window.location = 'http://www.user.com';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to user#hotmail.co.uk');
window.location = 'url';
</script>
<?php
}
?>
One possible problem is if the smtp server from which you are sending the emails, doesn't match the "from" email.
For example if you fill the from field with "yourmail#gmail.com" and the smtp server is not the gmail's one, this might be marked as spam by some mail providers. Unfortunately, there is nothing you can do about it, besides from sending emails from your own domain, that resolves to your smtp server.

Form worked on 1 and 1 host but not working on correct host

I have a form which I created in an asp page and this submits to a php page. This was working when I tested it in my host which is not where I want the files. I added it to the 1and1 host as this is what I use more frequently just to test it.
I needed it for my uncles site that is hosted on fasthost and the problem is I receive this error when I press send:
405 - HTTP verb used to access this page is not allowed.
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.
I don't understand this worked on 1and1 why would this not work on fasthost when I upload the files there?
I would highly appreciate any answers.
Thanks
Edit:
I have searched and searched and come across help files.
This problem seems to be something to do with the actual host and adding -f into the php file. I have still not got this working but would appreciate any help on this. The page I saw this on is http://www.fasthosts.co.uk/knowledge-base/?article_id=70
I have edited the php file and this is not working the php code is:
<?php
$name= $_POST['frmName'];
$email_from = $_POST['frmEmail'];
$field_phone = $_POST['frmPhone'];
$field_address = $_POST['frmAddress'];
$field_referral = $_POST['frmReferral'];
$field_frmCallback = $_POST['frmCallback'];
$field_frmEnquiry = $_POST['frmEnquiry'];
$email_to = 'info#moroccanpropertiesltd.com';
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email_from."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Address: '.$field_address."\n";
$body_message .= 'Referral: '.$field_referral."\n";
$body_message .= 'Callback: '.$field_frmCallback."\n";
$body_message .= 'Enquiry: '.$field_frmEnquiry;
$headers = "MIME-Version: 1.0\r\n";
$headers = 'From: '.$frmEmail."\r\n";
$subject = "Moroccan Properties Customer";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
$message .= "This is the text/plain version.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
$message .= "This is the <b>text/html</b> version.";
$message .= "\r\n\r\n--" . $boundary . "--";
ini_set("sendmail_from", "info#moroccanpropertiesltd.com");
$mail_status = mail($email_to, $subject, $body_message, $headers, "-finfo#moroccanpropertiesltd.com");
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'http://www.moroccanpropertiesltd.com/contact.asp';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to info#moroccanpropertiesltd.com');
window.location = 'url';
</script>
<?php
}
?>
I would be highly grateful if someone could point out what I have done wrong.
Thanks
Sounds like your hosting isn't setup to host .php pages? Have you tried using the .asp version? Usually you don't mix the two scripting languages.
You have to enable scripting with Fasthosts, its in the control panel under website, there is the ability to select different versions of PHP, and also ASP etc etc.

Categories