I'm newbie to PHP, HTML and to programming at all.
I'm trying to create a contact form with PHP and HTML.
Everything is working fine, and i'm able to get the e-mails.
Except of one thing, If i'm trying to fill the form with another language, In my case it's hebrew, The mail i'm getting is with gibrish.
I saved the html file with the UTF-8 encoding, and i added the meta code. checked my outlook encoding and checked the mails i'm getting with a webinteface and it's still gibrish.
Any ideas?
First of all, try to "Echo" the content of the email to the browser instead of sending it out.
If it displays correctly, you are fine on the website part.
If the text is coming from a POST or GET form, you might need to convert it
with htmlspecialchars_decode(), see
http://www.php.net/manual/en/function.htmlspecialchars-decode.php
Then you can take care about the format of the email.
If you are sending email, you need to set the proper headers for the email just as you do for the website. For UTF-8, you would do:
$headers = "From: ExRobot <robot#example.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .="Content-Transfer-Encoding: 8bit";
If your subject also might include foreign languages you can set it to
"=?utf-8?B?".base64_encode($subject)."?="
If this does not help, post a complete sample email here as you get it. this will help a lot to understand what is wrong.
Related
i am trying for send mail using php.My mail go to spam and some other errors are also in mail.
My header code is
$header_mail="select content from mail_header where id='1'";
$header_mail2=mysql_query($header_mail);
$fet=mysql_fetch_array($header_mail2);
$content= htmlentities($fet['content']);
$Headers = "From:$content\r\n" .
"Reply-To:$content\r\n" .
"Content-type: text/html; charset=UTF-8 \r\n";
$Headers.= "MIME-version: 1.0\n";
$Headers.= "Content-type: text/html; charset= iso-8859-1\n";
data in $content is zamisoft<zamisoft.com> but i got the mail as with
from: Zamisoft<
reply-to: Zamisoft<,
zamisoft#gmail.com>
I got the these message in mail
"Be careful with this message. Many people marked similar messages as phishing scams, so this might contain unsafe content. Learn more "
Mail is going to spam and errors are in header section part of mail.
Any body help me for solve these issue?
The problem is simple that the PHP mail() function is not using a well configured SMTP Server.
Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.
Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.
https://github.com/PHPMailer/PHPMailer
remove the htmlentities() from $content= htmlentities($fet['content']); and then try!
Since you are already setting the Content Type and Character Encoding, the contents of the array $fet['content'] will be read properly by the browsers!
htmlentities() converts the html tags to htmlentities (eg. < to <) which is what you are facing!!
Try it and let us know if the problem persists
Remove the line "Content-type: text/html; charset=UTF-8 \r\n"; as you have defined the header in the last line of header.
Add $Headers .= 'X-Mailer: PHP/' . phpversion()."\r\n"; at the last line of your code.
It tells which version of php is being used!
Also the email address should be a valid one as well!!
So I have a question that some more experienced individuals may be able to shed some light on and steer me in the correct direction. Here is what I have and what I am trying to do.
I have tinymce up and working just fine on a php webpage, of course that is until I go to submit it.
I am trying to use tinymce as the text editor for an email body that I am inserting into a vbscript then calling wsh to execute the .vbs. Everything works fine when I really don't edit the text. Just typing in and submitting without any colored text or other formatting.
However, if I do anything to the text at all it causes the .vbs not to execute. Upon opening up the unexecuted file I see that the "#" character for example when tinymce inserts the span color is causing it to hang.
I have googled and not found this issue presented is there something that I am missing? Or is there a better way to go about sending html emails from a webpage based text editor?
As I said as long as I don't really want to edit the text it works but I could do that plainly with a simple textarea but that defeats the purpose of wanting to be able to produce formatted emails.
Any and all suggestions are greatly appreciated. Thank you in advance for your time and help.
E-Mail Example:
// Sending an email with PHP
$to = $email; // Send email to our user
$subject = 'Email Sent with PHP'; // Give the email a subject
$message = '
<html>
<head>
</head><body>
<h3>Hey!</h3>
</body>
</html>
'; // Our message above including the link
$headers = 'From:nobody#nowhere.com' . "\r\n"; // Set from headers
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers); // Send our email
I have a form that will dynamically send emailers . This form takes the email id of the recipient ,the subject and the body content.
I am using PHPMailer class to go about this. When it comes to plain text ,the emailers work just fine. But I want to add a functionality where the users can paste html into the body part so that the emailer can parse/read them and send the html'ized version of the emails.
I tried this , but it didn't work as the the entire HTML was mailed as text.
$email_msg = htmlentities($_POST['mail_msg'], ENT_QUOTES, "UTF-8");
Any advice would be helpful .
Thanks in advance.
Did you set the PHPMailer default to HTML:
$mail->IsHTML(true);
Modify your mail headers :
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
So on a website I am working on there is an automated email sent when you register. When it sends it shows the css.
$body '<span style="color:#444444;">Header</span>';
I also tried this code that I found online that had style=\"asdas\" then used a command to remove the slashes but that didn't work either. Is there a simple php code that will just simply embed the html in the email?
First, make sure you put the $body = as #JamWaffles suggests.
Next, are you setting your headers correctly?
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
You can find a pretty detailed tutorial here: http://css-tricks.com/sending-nice-html-email-with-php/
It shows importance of headers, HTML vs txt email and user desires. It should be a good starting point for you.
You can also add a tld check in your code and assume they would have an html capable email client/web interface(gmail/yahoo/live etc) or you can just ask them to provide you with this information and then send them the emails in the format they have asked you to.
I would like to send HTML email with graphic elements included. I have no idea to attach garaphics to this email.
You probably don't want to do an inline attachment by hand, it's far easier, and less error prone to use a library, like PHPMailer.
It can attach the inline images, or if you give it some HTML code, it will attach the images by itself and modify the code to display them.
You can try Swift Mailer
I'm not going to bore you with a mediocre explanation here so instead let me link to this great tutorial over at Sitepoint which explained it to me in plain English! - advanced-email-php
The short version is that you are probably best off creating a HTML formatted messages, and using the header parameter of the php mail function.
$headers = "From: sender#example.com\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1";
mail(to#example.com, 'subject line', 'your message text <strong>with HTML in it</strong>', $headers);
The sitepoint.com article referenced by Jimmy provides an excellent and complete description of your options.