473,670 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to Sending Email in PHP with special characters using Swift Mailer

245 New Member
hey geeks,

I have a small mail script which will cause a PHP script to send a receipt upon clicking the submit button, by an HTML mail. This mail contains special characters, namely 'å', 'ä' and 'ö'. Whatever I try, I can't get these characters to display properly everywhere. In some email clients, these characters show up just fine, whereas in others they show up as question marks or kinda boxes. I've tried sending the mail as UTF-8, as ISO-8859- but I'm seriously stumped.

How do I send a mail from PHP using any characters while guaranteeing that the mail shows up the same everywhere?

I am using Wift Mailer library in order to send email.

Here is my swift mailer script settings

Expand|Select|Wrap|Line Numbers
  1. require_once 'lib/swift_required.php';
  2. $transport = Swift_MailTransport::newInstance();
  3.  
  4. //Create the Mailer using your created Transport
  5. $mailer = Swift_Mailer::newInstance($transport);
  6. $message = Swift_Message::newInstance()
  7.  
  8. ->setSubject($subject)
  9. ->setTo(array($cust_email => $name))
  10. ->setFrom(array('info@mohsinrafique.com' => 'Mohsin Rafique'))
  11. ->setSender('noreply@mohsinrafique.com')
  12. ->setReturnPath('bounce@mohsinrafique.com')
  13. ->setPriority(3)
  14. ->setCharset('utf-8')
  15. ->setBody($messagebody, 'text/html');
  16.  

Kindly help me out to sort out my problem.
Dec 10 '09 #1
9 8242
Dormilich
8,658 Recognized Expert Moderator Expert
does the HTML mail itself contain any information about the used encoding?

testing myself (Swift 4.0.3 on Linux, Thunderbird 3.0 on Mac, XHTML/UTF-8), I had no problems.
Dec 10 '09 #2
neovantage
245 New Member
Hmm yes and no too. I mean some static information like subject which is hard coded means

$subject="Bestä tigungsmail";

and some dynamic information came from database but that information is an entity which is encoded by this function

Expand|Select|Wrap|Line Numbers
  1. function charset_decode_utf_8($string) {
  2. /* Only do the slow convert if there are 8-bit characters */
  3. /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
  4. if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))
  5. return $string;
  6. // decode three byte unicode characters
  7. $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e","'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",$string);
  8. // decode two byte unicode characters
  9. $string = preg_replace("/([\300-\337])([\200-\277])/e","'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",$string);
  10. return $string;
  11. }
  12.  
so this is whole senerio about my html mail content. so how can i fixed that the mail shows up the same everywhere?
Dec 10 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
what I mean is, does your HTML contains a line as this?
Expand|Select|Wrap|Line Numbers
  1. <meta http-equiv="content-type" content="text/html;charset=utf-8">
Dec 10 '09 #4
neovantage
245 New Member
Yes but even then it is not working:(
Dec 10 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
as some mail clients display the data correctly, it seems that the others don’t support HTML email (good enough) or the encoding. what about a multipart message (html + text)?
Dec 10 '09 #6
neovantage
245 New Member
Yes i am doing this too. here it go.....!
Expand|Select|Wrap|Line Numbers
  1. ->setBody($messagebody, 'text/html');
Dec 10 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
that’s not multipart, that’s the mime type of the message body.
Dec 10 '09 #8
neovantage
245 New Member
Then:(
Will you ellaborate it more
Dec 10 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
ref. SwiftMailer Documentation: Setting the Body – and adding alternative body content (example in the wiki)
Dec 10 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1712
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Suppose you want to spam your friend, and you have lots of # friends. The solution is to write a program to do it. After a gander # at python docs, one easily found the module for the job. # see http://python.org/doc/2.3.4/lib/SMTP-example.html # the code is a bit long with the command line, but the key lies at # the bottom four lines. The gist is this:
1
2349
by: Roy Danon | last post by:
Hi, I'm trying to use ASPmail in order to send an email, for some reason the email arrives to the recipent but the body isn't sent with it and the subject is shown as question marks(encoding problems probably) This is the code : Set Mailer = Server.CreateObject("SMTPsvg.Mailer") Mailer.FromName = mailer.EncodeHeader(fromtitle) Mailer.FromAddress= from Mailer.RemoteHost = "localhost"
11
2557
by: Jonah Olsson | last post by:
Hi guys, I'm trying to figure out how to use MailMessage to send mails with a different return path than the sender if the delivery fails. Here's the case: Sender: Joe's Pizza Sender email: joe@pizza.com Receiver: Matt Hill (from repository)
4
2242
by: Robert McNally | last post by:
Hello, I'm currently learning c# and have been trying to write a simple program with sockets. The problem is i'm trying to send an email with an attachment, (which is the program itself) by using base64. When i run it it sends the email ok, but and attchment doesn't work i get an error when i run it. The attchment seems to be bigger (20k) then the orginal (16k) i've included the source which i have been using. Can someone tell me what...
1
3493
by: krishan123456 | last post by:
i have tried to send email with attached doc file but when i receive the mail i find the attached file in encoded text instead of actuall attachment.the code that i used to send an email is given below. function SendMail123($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles){ $OB="----=_OuterBoundary_000"; $IB="----=_InnerBoundery_001"; $Html=$Html?$Html:preg_replace("/\n/","{br}",$Text) or die("neither text nor...
2
4552
by: prasenjit2007 | last post by:
Hello, can u help me sending Email with attachments using the Class phpMailer. On the website I have a link to an html form in which I input the parameters with the names 1)from(textbox name) 2)To 3) Subject 4) Message5) File input(name abc) - to be sent as an attachment. This form calls the Class PhpMailer through another form with the following code to send the mail. <?php ini_set("include_path",...
7
9791
by: undbund | last post by:
Hi I am creating a newsletter system. The software should run from desktop computer (localhost) but be able to send email to anyone on the internet. Can you guys give me some ideas on how to achieve this. Thanks
10
5078
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area> <zone>BOXING</zone> <status>Running</status> <job>1000139233</job>
7
3758
by: Jason1983 | last post by:
Hello sir, When iam trying to send emails to my user accounts which are gmail id's using my application it is giving me this error. Here is the error... Server object error 'ASP 0177 : 800401f3' Server.CreateObject Failed Not sending CDONTS created e-mails. Here is the related code .... '******************************************************** 'Creating CDONTS mail object and sending mail to user
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.