include cc in php mail function - php

When I`m trying to insert cc with the php mail function I get only message with the HTML part.
I`m using the following code
$headers = "From:someone#gmail.com\r\n";
$headers .= "CC:test#gmail.com\r\n";
$headers .= "Content-type: text/html\r\n";
$to ="$x_email";
$subject ="Your Order Confirmation";
$bodyadmin=$messageadmin;
$sentmail=mail($to, $subject, $bodyadmin, $headers);
Could any one please help me to solve this issue?

$headers = "From: $from_email\r\nReply-To: $from_email";
$headers .= 'Cc: test#test.com\r\n';
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";

Related

PHP headers code does not display address in email, instead show server default address

I tried many alternatives to this code but it does not show my display name.
$to = $email;
$subject = $subject;
$message = $msg;
$headers = 'From: info#test.com \r\n';
$headers .= "Reply-To: info#test.com \r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
try adding in the following convention.
$headers .= 'From: Mysitename <mysitename.com>' . "\r\n";
http://php.net/manual/en/function.mail.php
Ok I manage to make it work by re-arranging the headers, thanks for your input Ori.
$to = $email;
$subject = $subject;
$message = $msg;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From: Info <info#testsite.com>' . "\r\n";

How to send email using php with sender name and email address by without server name?

How to send email using php with sender name and email address by without server name ?
I want to send email with name : NUMBERONE and email address : admin#NUMBERONE.com
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:NUMBERONE(admin#NUMBERONE.com)\r\n";
mail($to, $subject, $message, $headers);
I try above code , it's not send email. How can i do that ?
Example #4 in the documentation for PHP mail() function answers your question.
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
In your case it should be:
$headers .= 'From: NUMBERONE <admin#NUMBERONE.com>' . "\r\n";

Bit strange behavior of php mail function

By mistake, I added from-address as to-address in mail-function.
It sends mail to both to-address and from-address why? Is it documented anywhere?
$from = 'from_user#gmail.in';
$to = 'to_user#gmail.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$message = json_encode(compact('to', 'from', 'headers'));
// NOTE THE FROM INSTEAD OF TO
mail($from, $subject, $message, $headers);
Further to the comments and to highlight your request for reference. Here is a snippit from the php manual for reference. Notice the first line of additional headers:
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
So you are sending an email both through the mail($to... (which happens to be the $from in your case) but you are also sending the $to in the $headers declaration.

PHP Email with Static and Variable CC

I'm trying to create an email form where some addresses are fixed, and additional ones are variable, taken from a text field.
Is is possible to concatenate the CC header in such a way?
$headers .= "CC: fixed#email.com, fixed#email2.com\r\n";
$headers .= "CC: ".$additional_emails."\r\n";
Yes it's possible, but you're doing it wrong.
$headers .= "CC: fixed#email.com, fixed#email2.com";
$headers .= ", ". $additional_emails;
$headers .= "\r\n";
Assuming $additional_emails is comma separated.
It also be worth while checking to see if $additional_emails has a value.
$headers .= "CC: fixed#email.com, fixed#email2.com";
if( strlen($additional_emails) > 0 ) {
$headers .= ", ". $additional_emails;
}
$headers .= "\r\n";
If $additional_emails is an array, you can use implode().
$headers .= "CC: fixed#email.com, fixed#email2.com";
if( count($additional_emails) > 0 ) {
$headers .= ", ". implode(",", $additional_emails);
}
$headers .= "\r\n";
Tray it
$to = 'abc#gmail.com';
$subject = "Hii";
$message = "";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <abs#gmail.com>' . "\r\n";
$headers .= 'Cc: xyz#gmail.com,xyz#gmail.com,'.$email. "\r\n";
$mail=mail($to,$subject,$message,$headers);

PHP mail displaying content type header inside the body

I'm making a form, when it submits it sends you a HTML email with a confirmation that you submitted it correctly.
When I receive the email; the content type header is inside the body of the email and the HTML code is displaying as raw text.
Screenshot:
Here is my code:
$to = 'myemail#gmail.com';
$subject = "HTML email";
$body = "<html><body><h1>Hello world!</h1></body></html>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <webmaster#website.com/>' . "\r\n";
mail($to, $subject, $body, $headers);
Could anyone please tell me what exactly is going wrong?
Thank you
Change your below three lines
From
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <webmaster#website.com/>' . "\r\n";
To
$headers = "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type:text/html;charset=iso-8859-1" . PHP_EOL;
$headers .= 'From: <webmaster#website.com/>' . PHP_EOL;
I think after that this will work properly

Categories