I'm getting an error in my mail() function.
PHP Warning: mail(): Multiple or malformed newlines found in additional_header
While I was googling I came across some suggestions. but removing multiple new lines in additional_headers did not work. How can I fix this?
$separate =md5(time());
$el=PHP_EOL;
$headers = "From: ".$sndr.$el;
$headers .= "Reply-To: ".$sndr.$el;
$headers .= "MIME-Version: 1.0".$el;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separate."\"".$el;
$headers .= "Content-Transfer-Encoding: 7bit".$el;
$headers .= "This is a MIME encoded message.".$el;
$headers .= "--".$separate.$el;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$el;
$headers .= "Content-Transfer-Encoding: 8bit".$el;
$headers .= $message.$el;
You're inserting your message into your headers:
$headers .= $message.$el;
so you'll have
From: someone#somewhere.com
blah: blah
Hi mom!
Content-type: blah blah
which is an illegal email.
Related
I'm using PHP to send out a multipart/mixed message (plain text, html and attachments). However, whilst it works for most accounts, Yahoo, GMail and Sky seem to show blank emails. Where as everything else seems to display the email. ANY HELP WOULD BE GREATLY APPRECIATED!
My headers are
$headers .= "Content-Type: multipart/mixed; boundary=\"mixed-" . $random_hash . "-mixed\"\n";
$headers .= "MIME-Version: 1.0\n";
And the content is;
--mixed-7df05b31-mixed
Content-Type: multipart/alternative; boundary="alt-7df05b31-alt"
--alt-7df05b31-alt
Content-Type: text/plain; charset=utf-8
Hello how are you? I am just checking the mailing function.
Hopefully this will work!
Cheers.
--alt-7df05b31-alt
Content-Type: text/html; charset=utf-8
<div style="font-family:Arial, Helvetica, sans-serif; font-size: 10pt;">
<div>
Hello how are you? I am just <b>checking</b> the mailing function.<br><br>
Hopefully this will work!<br><br>
Cheers.</div></div>
--alt-7df05b31-alt--
--mixed-7df05b31-mixed
Content-Type: text/plain; name="abc.txt"
Content-Disposition: attachment; filename="abc.txt"
Content-Transfer-Encoding: base64
SEVMTE8gSlVTVCBURVNUSU5HIC4uLiA=
--mixed-7df05b31-mixed--
It may be an artifact from pasting, but try removing the blank space at the end of each boundary. (Highlight the text and you'll notice the boundaries have an extra space, but the closing boundaries-- do not)
Please verify whether your code is look like the following because the following code is working fine for me.
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $msg."\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type:application/html; name=\"".$filename."\" \r\n"; // use different content types here
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";
Don't build your own MIME messages. use Swiftmailer or PHPMailer to do it for you.
I'm trying to send an email with an hebrew content but I can't get it right.. that's the header that I use:
$headers = "From: $from" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=ISO-8859-1";
For example, if I want to send:
איזה יום יפה היום
And the result I get instead of hebrew text is:
טקסט: שדגשדגשדגשדג
According to this Wikipedia entry, the ISO/IEC 8859 series of standards define hebrew characters in part 8, not part 1. Thus, you must specify
$headers .= "Content-type: text/plain; charset=ISO-8859-8";
instead of
$headers .= "Content-type: text/plain; charset=ISO-8859-1";
in your code.
Anyway, it might be a good idea to use the UTF-8 encoding:
$headers .= "Content-type: text/plain; charset=UTF-8";
This allows you to send e-mails containing characters from different scripts or use special characters, eg. math characters.
Try giving out with this headers:
$headers = "From: $from" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8";
We are trying to send an email using sendmail. Everything works fine with normall headers but the moment we add attachment in the header, the sender name comes as Apache. Here is our code snippet
$from_email = "noreply#domain.com";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "attachment.pdf";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$text = "Hi!";
// main header (multipart mandatory)
$headers = "From:".$from_email.$eol;
$headers = "Bcc:user#domain.com".$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$message .= $text.$eol.$eol;
// attachment
$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf".$eol;
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--".$eol;
$b = mail($email, "Your Issue of the STQ",$message, $headers, "-fnoreply#domain.com");
By Adding -fnoreply#domain.com, we are getting like this in email header From: noreply#domain.com (Apache). Not sure where this Apache is coming from?
What could be the problem here.
Thanks
You need a dot on the second line.
$headers = "From:".$from_email.$eol;
$headers .= "Bcc:user#domain.com".$eol;
Make the header like this :
$headers .= 'From: <webmaster#example.com>' . "\r\n";
Also missing the dot on the second line as xyzz pointed
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP Mail, CC Field
I am using the following php to send an email. I need to add cc to my email. When I try to insert into header the html message show the raw html. What is the best way to handle a cc?
Thanks
$headers = "From: $from_email\r\nReply-To: $from_email";
$headers .= "Return-Path: <info#premierinspectiontn.com>";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
just tested this, and it worked as expected:
$headers .= 'Cc: test#test.com\r\n';
$headers .= 'Bcc: test#test.com\r\n';
I would also suggest moving your carriage return and new line to the end of the previous entry to $headers
$headers = "From: $from_email\r\nReply-To: $from_email";
$headers .= 'Cc: test#test.com\r\n';
$headers .= 'Bcc: test#test.com\r\n';
$headers .= "Return-Path: <info#premierinspectiontn.com>\r\n";
// add boundary string and mime type specification
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
hope that helps
Try adding
$headers .= 'CC: other#url.com' . "\r\n";
I want to format content of the mail to show the content in different line.
here is my message contetn.
bu the \n and \r is not working in this case. it just shows all the content in one line.
$message = 'Thank you for using . We really appreciate your business.'."\r\n".'If you are making your payment by mail, please make the check out to "blah blah" and send it to:'."\n".'blah blah '."\n".'blah blah'."\n".'San Gabriel, CA 91776'."\n".'Please see the attached invoice in PDF format for easy saving & printing purposes.';
$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($_POST['add6'],$subject, $message, $headers);
how can i do that?
You're telling the email client the message is HTML, so the CR LF combination will be treated like any other whitespace.
To fix this, change the content type to show you are sending a plain text email
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;
Alternatively, turn your message into an HTML message - an easy way to do that in your case would be to run it through nl2br to turn the newlines into <br> tags
Yep you've got Content-Type: text/html, so the CR LF is being treated like whitespace. Either send it as Content-Type: text/plain or call nl2br on your contents.
Your content type is HTML so you should use br or p tags instead of line feeds
For \n to work it needs to be double quotes, not single. "\n" is the right thing, '\n' is wrong and will not work.