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";
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 have made my contact form and it's working good except that when someone send me a message it comes without any format like the image below:
this is my .php code that i use:
$formdata = array (
'name' => $name,
'city' => $city,
'message' => $message
);
if ( !( $formerrors ) ) :
$to = "me#sipledomain.com";// input my name address to get mail to
$subject = "From $name";
$message = json_encode($formdata);
if ( mail( $to, $subject, $message ) ):
$msg = "Thanks for filling out the form, i will contact you soon";
else:
$msg = "Problem sending the message";
endif; // mail form data
endif; // check for form errors
endif; //form submitted
thanks in advance
json_encode() encodes your array into a single line of text designed to be decoded later, not for reading by humans.
Instead I would build your email message yourself by writing your own HTML or by giving it line breaks. You could do it programmatically by parsing/iterating through your array.
Eg:
$message = 'Name: '.$formdata['name'].'<br />'.$formdata['city'].'<br />'.'...';
If you really want to encode into JSON, you will need to do parse the JSON after you encode and do the same thing.
You might want to look into a flag when you call json_encode() called JSON_PRETTY_PRINT which will keep whitespace. More info: http://www.php.net/manual/en/json.constants.php
In use: $message = json_encode($formdata, JSON_PRETTY_PRINT);
For playing with JSON I like to use tools like http://jsonmate.com/ that formats JSON into a neat tree.
If you want, send the email as formatted HTML by wrapping everything in standard HTML tags. Otherwise, PHP sends messages as unformatted, so use \n to break lines etc.
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.
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 a form with more than 20 input fields. The PHP mail function is not working since it can only accept 5 parameters. How can I send these values to my email address?
$to = 'myemail#mydomain.com';
$subject = 'form values';
$message = '';
foreach( $_POST as $key => $ value ) {
$message .= $key . ' => ' . $value . '<br>';
}
mail( $to, $subject, $message);
The parameters in the PHP mail() function have different meaning. They are not the data, sent to the user. Try using the following script and if it works - format the $message to match your requirements.
$email = 'rec#example.com';
$subject = 'Subject';
$message = print_r($_POST,true);
mail($email,$subject,$message);
More information can be found # http://php.net/manual/en/function.mail.php
Well I don't know what kind of input fields you have, but they could all be passed in the "subject" field. However, if you have a sufficiently complex email to send, and you really need to write everything yourself, you should look into PEAR.
So either add the 20 input fields onto the subject $subject .= 20things or use a tool that is inherently secure without having to remember to escape input and validate using regex.