Multiple recipient mail php not working for second onwards addresses - php

I have an HTML email needed to be sent to more than one person:
$mem = "abc#def.com, qwr#rty.com";
$subject = 'Invitation to Party';
$headers = "From: info#example.com\r\n";
$headers .= "Reply-To: info#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "SNIPPED";
mail($mem, $subject, $message, $headers);
It is sending to the first email which is abc#def.com, but it's not sending mail for the second recipient which is qwr#rty.com and the rest.
The email addresses are examples.
Is there any work-around for this besides using library?

you may send the second id as a bcc,
$headers .= "Bcc: ".$bcc."\r\n";

Related

How to create email content type to multipart/mixed in php

I have a website contact form that sends as an email to my iPhone. The problem is I am getting the following message:
"This message cannot be displayed because of the way it is formatted. Ask the sender to send it again using a different format or email program. multipart/mixed"
Is this has something to do with email content-type and how to fix it in my PHP code.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$sender_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message_body));
$sentMail = mail($recipient_email, $subject, $body, $headers);
You specify the Content-Type as a header string.
Assuming you are appending your headers with the standard dot notation, you would use:
$headers .= "Content-Type: multipart/mixed";
And later this would become the fourth parameter of your mail() function:
mail($address, $subject, $message, $headers);
Here's a basic example:
$address = 'sample#sample.com';
$subject = 'Subject';
$message = 'Message';
$headers = "From: My Name<something#something.com>\n";
$headers .= "Reply-To: something#something.com \n";
$headers .= "Content-Type: multipart/mixed";
mail($address, $subject, $message, $headers);

PHP mail possible to reply to an email?

I'm attempting to reply to an email from a php applicaiton. I use php imap to retrieve emails from the mail server. I now want to reply to those messages. I have the message_id returned from imap_fetch_overview. How do i use these values to reply to the email? I tried In-Reply-To but when i check the email the message shows up as a new message rather than a reply to a message.
$overview = imap_fetch_overview($inbox,$email_number,0);
$headers = "From: <test#domain.co.uk> \r\n";
$headers .= "In-Reply-To: ".$overview[0]->message_id."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "testing";
$message = "test message2";
mail( "test2#domain.co.uk", $subject, $message, $headers );
How do i solve?

Undisclose recipients php without any extensions only mail() function

I am trying to not disclose the recipients when I send an email but I am failing on this:
$email = implode('; ', $email); // array where I have the emails
$to = $email; // webmaster#domain.com; webmaster#anotherdomain.com
$subject = 'Subject';
$headers = "From: noreply#domainfromwhereisendemail.com\r\n" . "X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "To: Undisclosed Recipients <noreply#domainfromwhereisendemail.com>\r\n";
//$headers .= "Cc: $to\r\n";
$message =
<<<START
This is the message
START;
mail($to, $subject, $message, $headers);
I tried adding Cc or Bcc, but not working, it is adding besides the emails Undisclosed recipients. I am trying to do this without any other extensions, I checked a lot of questions from stackoverflow here but did not accomplish this. Emails are still being shown to each.
Nope you can't stop that from nondisclosure, unless you send the emails separately using a loop.
$email = implode('; ', $email); // <---- Don't do this.
The loop up way..
foreach($email as $mail) #<---- Use a foreach and loop through
{
$to = $mail;
$subject = 'Subject';
$headers = "From: noreply#domainfromwhereisendemail.com\r\n" . "X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message =
<<<START
This is the message
START;
mail($to, $subject, $message, $headers);
}
Here is the ôkio solution with a single call to mail():
$subject = 'Subject';
$headers = "X-Mailer: php\r\n";
# $headers .= "MIME-Version: 1.0\r\n"; # do you really need that?
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
foreach($email as $mail){
$headers .= "Bcc: ".$mail."\r\n";
}
$message =
<<<START
This is the message
START;
mail('non#existing.email', $subject, $message, $headers);

php mail Cc not sending email if left blank

I am not sure if anyone can help me with this issues but I currently have a php mailing form. everything works great, I am trying to setup Cc options.
code.
$subject = "Name #$name_id test data";
$mailer ='Company <Support#company.com>';
$headers = "From: $mailer \r\n";
$headers .= "Cc: $cc \r\n";
$headers .= "Reply-To: ". strip_tags($mailer) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body style="background:#eeeeee">';
mail($emailto, $subject, $message, $headers);
cc var is $cc=$VAR["cc_user"]; which is linked to html form. so here is I enter an email address in the html input form and submit, it works. if I leave blank, email does not send. can anyone help me with this.
Thanks so much.
Fixed..
$emailto= $sql['CUSTOMER_EMAIL'].", ".$VAR["cc_user"];

custom php email settings?

I have this logic
$subject = "something.com Signup -
Please do not reply to this email. It was automatically generated.";
$body = "A new person has signed up to receive something updates:";
$headers = "From: webinquiries#something.com\n";
$headers .= "Reply-To: something#gmail.com\n";
// $headers .= 'Bcc: something#something.com' . "\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\n";
mail($email, $subject, $body, $headers);
which seems ok but one thing.... can i set the smtp info like this
server="smtp.something.net",
username="webinquiries#somthing.com",
password="asda.1sda",
port="587"
you can set the server in php.ini, but user\password as php's build in mail does not support authentication. you should look at a third party library (phpmailer) as the php mail() function's very under powered.

Categories