I have a PHP Mail script that sends out emails and I need to send some out in Chinese. I have the following code:
$email_header = "From: $from\n";
$email_header .= "X-Priority: 1\n"; //1 UrgentMessage, 3 Normal
$email_header .= "Return-Path: <$return>\n";
$email_header .= "Content-type: text/html; charset=utf-8\n";
mail($row["email"], '=?UTF-8?B?'.base64_encode($subject).'?=', $email_body, $email_header);
The issue I have is with both the Subject of the Email and the body - it is sending as follows:
Subject: ???????????
Body: ???????????????
?????
??????????????????????????????????????????????????
?????
Clearly not Chinese!!! If anyone can point me in the right direction, that would be great.
Thanks in advance,
Homer.
Looks like a database connection issue rather than a mailer issue. Perhaps forgot to do a set names utf-8...?
Related
I am struggling to send a mail via perl script to people in cc list. The actual recipient is receiving the email with proper contents. But the email-address in ccList is not receiving the email.
$smtp->data();
$smtp->datasend("From: $supportEmail\r\n");
$smtp->datasend("To: $toAddress\r\n");
$smtp->datasend("Cc: $ccList\r\n");
$smtp->datasend("Subject: " .$subject. "\r\n");
$smtp->datasend("\r\n");
#Send the message.
$smtp->datasend("$message");
$smtp->datasend("\r\n");
$smtp->dataend();
There are more than one valid email address in $ccList
$ccList = 'xyz#gmail.com,pqr#gmail.com';
Bad recipient address syntax
is what I get in logs.
You'll need to notify the server of all the recipients first. The code should look something like this:
$smtp->mail($supportEmail);
$smtp->to($toAddress);
$smtp->cc($ccList);
$smtp->data();
$smtp->datasend("From: $supportEmail\r\n");
$smtp->datasend("To: $toAddress\r\n");
$smtp->datasend("Cc: $ccList\r\n");
$smtp->datasend("Subject: " .$subject. "\r\n");
$smtp->datasend("\r\n");
#Send the message.
$smtp->datasend("$message");
$smtp->datasend("\r\n");
$smtp->dataend();
I try to download emails from my POP3/IMAP accounts using Zend Framework 1.12 and it's working fine. QP header fields will be decoded automatically. However, when a header field (from name or subject) is base64 encoded like this:
=?UTF-8?B?c3DEvsWIYcWl?=
it will not automatically base64 decode it. Don't know why. While it would be easy to fix this "my way", I would like to do it right.
Can anybody recommend a good approach how to deal with base64 headers?
Thanks a lot.
You can use use iconv_mime_decode_headers() PHP function.
$decoded = iconv_mime_decode_headers('Subject: '.$subject, 0, "UTF-8");
var_dump(decoded['Subject']);
Note, that you can pass multiple header parameters to one function, by separating them with newline or "\n". e.g.
$headers = "Subject: {$subject}\nFrom: {$from}";
$decoded = iconv_mime_decode_headers($headers, 0, "UTF-8");
In this case you will get array with keys "Subject" and "From" with decoded data.
Its the responsibility of mail mime parsers to decode the mail headers. There are open source base64 decoders available on net which can be used to decode these strings.
This question already has answers here:
Why is my e-mail still being picked up as spam? Using mail() function
(5 answers)
Closed 9 years ago.
I am sending an email using PHP but all the emails are going to the spam folder. Please tell me where I am making a mistake.
<?
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$ToEmail = "me#example.com";
$ToSubject = "Message from your site";
$EmailBody = "Name: $name\n
Email: $email\n
Phone: $phone\n
Message: $message\n";
$Message = $EmailBody;
$headers .= "Content-type: text; charset=iso-8859-1\r\n";
$headers .= "From:".$name." / ".$email."\r\n";
mail($ToEmail,$ToSubject,$Message, $headers);
header("location: thankyou.php");
?>
Long story short, if the recipient's server put your mail into the spam box, your program is working all right and there is nothing you can do.
Longer Story: Nowadays most mailing servers will check that the email is from a server that actually holds the domain corresponding to the email. Suppose you are sending with account abc#gmail.com, the server of the recipient's email checks if the server from which this mail comes is gmail.com. This is done by checking the SPF record .
I just installed ssmtp to send email with LAMP on Ubuntu.
And a simple script like this:
<?php
$additional_headers = 'From: someone#testing.com' . "\r\n";
$res = mail('myemail#gmail.com','test','test body', $additional_headers);
var_dump($res);
?>
I received the email but the sender name will put as "nobody" , so it is using the user name "nobody"? How can I change it? I'm new in Ubuntu...
Thanks.
Try changing your "Extra Headers" to also include a 'Reply-to' header EG:
$additional_headers = 'From: someone#testing.com' . "\r\n" .
'Reply-To: someone#testing.com' . "\r\n";
The way you have it SHOULD work, according to the documentation, but distance can vary depending on which MTA (Mail Transport Agent) your using.
The doc page is here : http://php.net/manual/en/function.mail.php
Additional:
Be aware, that in a lot of mail systems, you need to provide a valid DNS address too. On my mail server running ubuntu, if I give the from header as a domain that cannot be looked up using a valid DNS, the recipient address will appear blank.
I pray someone can help me. I've been around and around...
The situation is this. I have visible encrypted email addresses that an individual takes and puts into a form (enctype="multipart/form-data)and completes the email form prior to mailing. My php on a different page attempts to decrypt the TO: field of the html email form.
This is my php code, testing to see if I indeed am decrypting:
if (isset($_POST['submit'])) {
//just to echo the encrypted input for the email to field ECHOES PERFECTLY
$to = $_POST['to'];
echo $to;
//above echo displays correctly below is a jumbled mess
echo "<br>";
$ivs = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_OFB);
$iv = mcrypt_create_iv($ivs, MCRYPT_RAND);
$key = "12yeshua34";
$message = $to;
$enc = mcrypt_decrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_OFB, $iv);
echo $enc;
}
This is what gets echoed:
feeb936a8e9896a849c67f011524f6f2e4d8
$p�������t���b�� �'����T���A�f~
As you can already tell I am also a newbie. And I believe I've read everything I could find... and I still can't solve this. If I could get this to decrypt, then I could remove the test portion of this code and get an email 'successfully sent off.
Thank you and FATHER BLESS jim
assuming your encryption process works fine and uses 3DES in OFB mode to encrypt the address with the provided key "12yeshua34", you will also need the IV used for encryption for that specific address in order to be able to decrypt ... mcrypt_create_iv($ivs, MCRYPT_RAND) will create a random IV each time ... you need the very same IV for both operations: encryption and decryption