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?
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 am using encodeURIComponent to send value to php script
?txtAra = encodeURIComponent($("#textAra").val())
I saw in firebug it sends line break as %0A, in php script i am using
$txtA = $_POST['txtAra'];
and php mail function, in email i sees as test\n\n\ntest\n\n\ntest
How do i make \n as normal line break in mail?
i tried str_replace and nl2br, still same.
Any idea why?
What header type you are setting in mail ?
text
or html ?
I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out.
The following is the code that doesn't seem to work.
while(...) {
$msg .= "<img src=\"http://.../images/".$media['Path']."\"><br>";
echo "message: ".$msg."<br>";
}
What I want is for $msg to contain a bunch of images (provided by $media['Path']) that are separated by line breaks. Then $msg is passed into mail().
The echo confirms that no images are being sent. And, indeed, I receive no images in the email body. Why is this happening? How can I fix it?
There are two ways of embedding images in an email:
As external references: <img src="http://..."; and
Embedded in the email.
(1) is I guess what you're trying to do. Many mail programs will (rightly) block such images as they are used by spammers to test email accounts for liveness.
It's better to do (2). See PHP Email: Using Embedded Images in HTML Email. Basically you create a multi-part MIME email (so you can attach HTML and the images) and then reference them by cid instead of a true URL. These are far less suspicious to any mail program that receives them but obviously result in bigger emails (as the image might be sent 100,000 times instead of just sending a URL).
Have you inspected the HTML that gets echo'd out? You probably have the wrong image path. Also, if you're going to be emailing that, you need to use an absolute path (http://yoursite.com/images/theimage.jpg rather than images/theimage.jpg).
Also, make sure that you have the headers set up right in the mail() function so that it gets sent as HTML instead of plaintext.
You could also use a mail wrapper such as Swiftmailer or PHPMailer which may help you with your problem. You have said that you are on a time limit though, so it may take you longer to actually convert across to using something like this.
to echo the angle brackets use:
< //<=
> //>=
I think php can not deal with angle brackets as it is:
try the following:
$varone='one';
$vartwo='two';
$b=' <';
$concateOne='With Normal Brackets : '.$varone.'<'.$vartwo.'>'.'<br>';
$concateTwo='With Character Brackets : '.$varone.'<'.$vartwo.'>'.'<br>';
echo $concateOne;
echo '<br>';
echo $concateTwo;
echo '<hr>';
var_dump($concateOne);
echo '<hr>';
var_dump($concateTwo);
echo '<hr>';
when dumping the variable you will find that php do not store the value of the normal brackets.
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.