How can i put commas in the 'From:' field of the mail headers??
For example with "From:Javier, My Site" when i read the email sended with any mail client like outlook, in the From only appears Javier#myinternalserverurl.com.
It cuts the from field by the comma... All the things that i found about 'From' field in php mails says that if you put commas automatically is treated like a list of mails.. any suggestion?
Thanks in adevice!
"From: \"Javier, My Site\" <email#domain.com>" should work
Related
I have a variable say $message which contains the content to be sent in mail using php mail function. This variable $message will contain text that will also have line breaks. This variable data is being fetched from textarea of another file using ajax.
For instance, the actual text is:
Hello
This is a test message
So while sending mail ($message variable), I see Hello This is a test message, without line break. Is there a way to fix this?
You can use like that:
$message = str_replace ('<br>' , '\r\n', $_POST['textarea']);
You can also use nl2br() function here.
Make sue you are using HTML header in mail() function.
Im using php's mail() function to send an e-mail to multiple receivers.
If i enter as the first parameter of the "mail" function something like "example1#example.com,example2#example.com,example3#example.com,example4#example.com,example5#example.com,example6#example.com........" a string of more than 1000 characters, when I receive the e-mail I see a " "(an empty space) being inserted at about the 995th character and whatever e-mail was at that position is broken.
I read that this is because the mail server doesn't accept very long lines of string so you should insert a "\n" at every 70 or so characters.
Therefore, I tried using wordwrap($emailList) that should insert line-breaks.
Unfortunately this doesn't solve my problem and I'm running out of ideas right now.
Finally I was able to solve this problem like this:
I have the to list in a $strTo variable which contains the emails like this "email1, email2, email3, email4, "... with each email separated by ", " .
Before doing the mail() function I did this:
if($strTo != ""){
$strTo = wordwrap($strTo,900,"\r\n ");
$strTo .= "\r\n";
}
Which means I put carriage return, new line and a white space at every 900 characters(without breaking any words) and finally, at the end of the string I inserta carriage return and line feed.
wordwrap did not work for me. I guess it depends upon whether your mail server honor it or not. Also in my case the fold was occurring every 998th character.
I was able to solve using multiple 'To:' fields in message header. e.g.
header = <<EOF
From: xyz#xyz.com
To: abc1#abc.com, abc2#abc.com, abc3#abc.com, ...abc100#abc.com
CC: prq1#prq.com
Subject: 'my subject'
EOF
constructed multiple arrays of 20 each using array.each_slice(20). Then formed the header such that
header = <<EOF
From: xyz#xyz.com
To: abc1#abc.com, abc2#abc.com, abc3#abc.com, ...abc20#abc.com
To: abc21#abc.com, abc22#abc.com, abc23#abc.com, ...abc30#abc.com
To: abc31#abc.com, abc32#abc.com, abc33#abc.com, ...abc40#abc.com
CC: prq1#prq.com
Subject: 'my subject'
EOF
my mail server honored it.
I have a feedback form where the user can enter his/her feedbacks in a textarea. When the form is submitted I am using the php mail function to get all the user details into my mail.
mail( "aaa#ddd.com", "Subject: Comments posted by $postedBy", $message, "From: $emailID" );
Here $message is the user comments. But I get something like this in the email body.
Hi.test line break\r\nnew line\r\nnewline 2\r\ntest again\r\nagain.
The line breaks in text area are showing up in the mail. How can I fix this?
Edit:
$message = mysql_real_escape_string($_POST['comments']);
Are the \r\n directly displayed or is all in one line without seeing \r\n?
For last I think you have to set the correct content-type.
In example 4 on http://php.net/manual/en/function.mail.php you can see how to set the content-type. But you have to use plain/text for that.
EDIT:
After your edit: mysql_real_escape maskes all linebreaks. use $_POST['comment'] on your mail()-call to have it working!
mail($to, $subject, $_POST['comment'], $from);
There is some function in your code that replaces newline characters with \r\n.
just trace your code and see, where this replacement takes place, and remove it.
Not a big deal
I'm not sure if you've tried this but can you try replacing the "\r\n" with "<br>".
Alternatively see if you can change the email mime type
Check this
http://php.bigresource.com/Email-MIME-Types-KesYPexl.html
Zend Mail throws an exception (because mail() returns false) when the to name is set to something with both a foreign character (like "å") and a comma (","). Re-produce with code below.
$mail = new Zend_Mail('utf-8');
$mail
->setFrom('info#myhost', 'My company')
->setSubject('hi')
->addTo('MYEMAIL#SOMEHOST.COM', 'aå,a')
->setBodyHtml('<p>asd</p>')
->send();
If I change the addTo call to something of the below, no error occurs.
->addTo('znarkus#gmail.com', 'aåa')
->addTo('znarkus#gmail.com', 'a,a')
->addTo('znarkus#gmail.com', 'aa')
The weird thing is, even though it throws an exception ("Unable to send mail"), the mail is delivered. I'm running the latest Zend Mail (1.9.5?). Please halp!
It's just a bug in Zend_Framework:
http://framework.zend.com/issues/browse/ZF-10792
a comma is allowed in the name part of the e-mail:
"Smith, Frank"
this is okay
The problem is that mail() function for $to accepts
User <user#example.com>, Another User <anotheruser#example.com>
and I guess that PHP internally splits the string on commas to separate multiple recipients but you are providing only one email address.
If you think this is a Zend_Mail, or PHP bug you should post this to the appropriate issue tracker.
The comma is a reserved literal in the "to" part of a mail header (and you should never use it though), separating different targets. Even if your "first" mail gets sent, imho it creates a header like this:
aå, a <znarkus#gmail.com>
With this header i assume your mta tries to send two mails: one to aå, which fails (badly), and a second one to znarkus#gmail.com, which should make its way.
You could try to look into the mail headers to confirm this theory.
I'm using PHP _EOL when building the message body of my email but the line feeds are not getting through and the entire message body ends up one long line in the resultant email. This happens regardless of Multi-part or html only messages. Sending as text only it works fine, but of course I want to send Multi-part messages.... Any ideas?
Uhm. If there are no line breaks in your HTML email, it's probably because neither a \n nor a \r\n is a newline in HTML; a <br /> tag is.
I've never even used PHP_EOL before, but I wonder if it is set to the type of your server, not of the recipient. I don't see how a constant could be correct for all recipients, that doesn't make sense.
Usually '\n' is all that is needed... in some cases you may need '\r\n' depending on the protocol involved. What are you using to send the email? What are you using to view the email?