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.
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 --;
I am looking to send email to multiple recipients but i am not able to do so.. here is my code.
using print_r() statement
Array
(
[selectedvalue] => Array
(
[0] => muralidego#gmail.com
[1] => muralidego#yahoo.com
[2] => ezhil#emirates.net.ae
)
}
and i want to use this emails in mail($mailDO->toEmail)
mail($mailDO->toEmail, $mailDO->subject, $mailDO->message, $headers);
kindly help me out...thanks.
Use a foreach
foreach($yourarr['selectedvalue'] as $email)
{
mail($email, $mailDO->subject, $mailDO->message, $headers);
}
You can do a foreach loop like Shankar has posted, or you can add them to your headers as another cc.
$headers .= 'Cc: muralidego#yahoo.com' . "\r\n";
$headers .= 'Cc: ezhil#emirates.net.ae' . "\r\n";
Or if you don't want them to know, then you can do:
$headers .= 'Bcc: muralidego#yahoo.com' . "\r\n";
$headers .= 'Bcc: ezhil#emirates.net.ae' . "\r\n";
You need to combine all email addressed into single string to be used with mail().
mail(implode(',',$yourarr['selectedvalue']),$mailDO->subject, $mailDO->message, $headers);
Based on the tags you imply you are using MySQL. In that case you can already handle this as part of the query:
SELECT GROUP_CONCAT(DISTINCT email SEPARATOR ",") FROM your_table WHERE somerule=1;
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.
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.
of all the languages i know im the weakest in php...
I have a script... that takes a csv file and does some stuff with it... fairly simple.
the issue i am having:
in_array('username', $headers) ... returns null...
while...
print_r ($headers); shows username being the first entry in the csv.
thoughts? mistakes i may have made?
TIA
code here
/// Turn the string into an array
$rows = explode("\n", $this->raw_data);
/// First row includes headers
$headers = $rows[0];
$headers = explode($this->delimiter, $headers);
/// Trim spaces from $headers
$headers = array_map('trim', $headers);
/// Check that there are no empty headers. This can happen if there are delimiters at the end of the file
foreach($headers as $header){
if(!empty($header)){
$headers2[] = $header;
}
}
$headers = $headers2;
if(! in_array('password', $headers)){
/// Add password column for generated passwords
$headers[] = 'password';
}
/// Add status column to the headers
$headers[] = 'status';
$this->headers = $headers;
/// Check that at least username, name and email are provided in the headers
if(!in_array('username', $headers) ||
!in_array('name', $headers) ||
!in_array('email', $headers)){
echo "error\n";
return false;
}
You can use the built in str_getcsv() function. Try replacing the $headers variable assignment with
$headers = str_getcsv($rows[0], $this->delimiter);
Then find the value(column) you want and loop through the rest of the $rows using the same str_getcsv() function to get the matches you need.
You may want to use the file() function to grab the file in an array delimited by newlines to begin with, as well.
Check the first three functions in this list . Your problem can arise from several causes. Start by elimination of unnecessary parsing by using the built in CSV function.
I don't see code that sets $headers2 to be an array. Is the first assignment to that variable getting lost once the second assignment happens which turns it into an array?