My requirement is to send mail in turkish language in php.
Here is my code:
$rst2 = $this->selectQry(TBL_MAILSETTING,"mailTypeId='8' AND langId='1'",'0','0');
$query2= $this->getResultRow($rst2);
$subject2 = $query2['mailSubject'];
$subject2 = iconv_mime_decode($subject2, 2, "utf-8");
$subject2 = mb_convert_encoding($subject2, "utf-8","AUTO");
$subject2 = mb_encode_mimeheader($subject2);
$from1 = $_POST['email'];
$query2['message'] = $query2['mailContaint'];
$query2['message']=str_replace("[name]",$_POST[name],$query2['message']);
$message1 = $query2['message'];
mail(
$from1
, $subject2
, "$message1\r\n"
, "From: $from\n"
. "MIME-Version: 1.0\n"
. "Content-type:text/html;charset=iso-8859-1" . "\r\n"
. 'X-Mailer: PHP/' . phpversion ()
);
Here every thing is going well but the problem is the subject is going in encoded form as(Takım as Takım) in "evrimii Tebrik Card Designer Takım"
Any body can help will appreciated.
Just an advice: Don't use the built-in mail function. Use Zend Mail, or phpmailer or PEAR Mail, or any good mail package. The point is: A well developed package has solved major problems, also the problem you have asked (regarding encoding).
But anyway: Your question is down to wrong encoding in subject (this is for utf-8):
mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers);
More on the subject character set encoding here:
http://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/
As stated in the comments, you might have the encoded character already as ı in the database.
You can use html_entity_decode() (http://de2.php.net/function.html-entity-decode) to reverse the encoding.
Related
I'm using imap with php to get the body of my emails.
With what've coded so far, I am not getting the special characters and weird formatting at the end. For instance, if I send myself an email (with a regular email client such as Apple Mail) that says:
Test with characters é à and some ! that rock.
What I get with php is:
Test with characters =C3=A9 =C3=A0 and some ! that rock.=
I've tried re-sending the body through the mail function of php with those headers, but I'm still getting the same problem.
$headers="From: address#email.com" . "\r\n" . "MIME-Version: 1.0" . "\r\n" . "Content-type:text/html;charset=UTF-8";
mail($sendTo, $message, $noBody, $headers);
I've tried addslashes(), which didn't help either.
Sample of my code here:
$imapLink=imap_open("{".$mailbox."}INBOX",$username,$password);
$mailBoxInfos = imap_check($imapLink);
$mailList = imap_fetch_overview($imapLink,"1:".$mailBoxInfos->Nmsgs);
if(isset($mailList))
{
$numMess = imap_num_msg($imapLink);
while($numMess>0) {
$message = imap_body($imapLink, $numMess);
$numMess --;
}
}
$imapClose = imap_close($imapLink);
Hope you can help me with that!
Thanks in advance!
Arthur
The =XX you see in your text is called "Quoted-Printable Content". It's used to display character which can't be displayed in 7-bits.
You can use quoted_printable_decode() to convert it back to a readable string.
So this should work:
$message = imap_body($imapLink, $numMess);
$message = quoted_printable_decode($message); // <-- add this line
$numMess --;
If the clients email id is fatched using below code.
$message .= 'Email: '.$_POST['email']. "\n\r";
I guess $email is variable for client's email id. How do I send an email as BC to the client's email id?
Right now I am using only single email id using
$to = 'emailid#domain.com';
Update:
The email field value is <?php echo $_SESSION['email']; ?> in the form.
Update: I have pasted entire code at http://pastebin.com/5bWDQSk2
If you're running at least 4.3, you can set a Bcc additional header. PHP will interpret this internally before sending the message.
$headers = "Bcc: address#place.com\r\nFrom: me#place.com"; // etc
mail( $to, $subject, $message, $headers );
See the docs: http://www.php.net/manual/en/function.mail.php
Also note that because PHP doesn't expand escape sequences (\r, \n) when using single quotes, you must use double quotes for this string.
You have to add custom headers:
# bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
mail('recipient#host.com', 'Subject', 'Message', 'Bcc: emailid#domain.com' )
Add the BCC as a header e.g.
$header = "Bcc: john.doe#yahoo.com";
This is probably an easy question but I am not sure the proper syntax.
I am sending an email to my client - but my client also wants that person to receive the emails once they hit submit.
Currently its a POST php form and it works fine - but need to include the POST-email address that was entered into the form.
$from_email = $_POST['emailAddress'];
$to = 'owen#gmail.com';
AND I have mail($to, $subject, $message, $header..
So how do I rewrite the code:
$to = 'owenpiccirillo#gmail.com';
to have also send to the email submitted in the form? because this works.
$to = 'owen#gmail.com, whatever#aol.com';
but this doesnt work....
$to = 'owen#gmail.com' . $from_email;
Thanks in advance
-O
You need a comma and space in the $to concatenation:
NOT
$to = 'owen#gmail.com' . $from_email;
// results in 'owen#gmail.comwhatever#aol.com'
but THIS
$to = 'owen#gmail.com, ' . $from_email;
// results in 'owen#gmail.com, whatever#aol.com'
If this works:
$to = 'owen#gmail.com, whatever#aol.com';
then what exactly is the issue? The reason this doesn't work:
$to = 'owen#gmail.com' . $from_email;
is because there's no comma separating the values. So it would evaluate to:
$to = 'owen#gmail.comwhatever#aol.com';
which isn't a valid email address.
This is because the . is concatenating the two addresses together. So if you do an echo or print_r you would see something like this:
owen#gmail.comwhatever#aol.com
You need to add a comma:
// Value will be injected into the string with double quotes.
$to = "owen#gmail.com, $from_email";
Alternatively, you can use CC and BCC to send copies.
I have problem with cyrillic in the (From) part of the email. I had the same problem with the subject but i fixed it like that.
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
And these are my heders.
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
And still when i pass cyrillic , i get something like РЇРІРѕСЂ .
$headers = "From: асдафсддс <email#test.test>\r\n";
My from is something like this.
Try use
$headers = "From: =?UTF-8?B?".base64_encode($fromname)."?= <email#test.test>\r\n";
Email headers can exclusively contain ASCII characters. That's the reason you need to encode the subject, and it's the reason you also need to encode the From header. To do so, best use mb_encode_mimeheader. See the examples in its documentation.
Can anyone tell me on how to combine multiple form fields (which contain email addresses) and incorporate them into a $header CC: ?
I currently have this:
$headers .= 'CC: <'.$_POST['submitted_by'] ."> \r\nReply-To:<".$_POST['submitted_by'].">";
which works fine but I now need to add another field "sales" to the Cc: and everything I try does not work.
First, try to make it more "readable".
Try something like this:
$headers .="CC:<{$_POST['submitted_by']}>";
$headers .="\r\n";
$headers .="Reply-To:<{$_POST['submitted_by']}>";
Now, can't you just put it in the next line of the CC? I don't see where the problem is.
$headers .="CC:<{$_POST['submitted_by']}>";
$headers .=",<{$_POST['sales']}>";
$headers .="\r\n";
$headers .="Reply-To:<{$_POST['submitted_by']}>";
Last but not least. Remember to filter the fields! To prevent header injection.
// Verify submitted_by is a valid email address first and contains no line breaks
// Look elsewhere for how to do this.
// Additional addresses are comma-separated.
$headers .= "CC: $validated_submitted_by, $sales_addr\r\n";
$headers .= //other headers.