Forum Moderators: coopster

Message Too Old, No Replies

PHP Email question

         

PeteM

7:31 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Well they say that "the only stupid question is the one you don't ask" so....

I wish to insert a line break (carriage return) in an email that I'm sending using PHP. I tried '\r\n'. This didn;t work so I googled for a solution but can't find out how to do it. It must be really simple but I don't know how.

Thanks, Pete

s9901470

7:46 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Hi
I usually just put the carriage returns in the code itself, I don't know why but it seems to recognise it as such. The example below arrives with spaces after Dear, Welcome, This.

Ed

<?php
$fullmessage = "
Dear " . $fname . "

Welcome to the newsletter.

This month, blah blah blah

". $_POST[message] . "
";
} else {
$fullmessage = $_POST[message];
}

mail("$email_addr", "$_POST[subject]", $fullmessage, $headers);

}

echo "<center>email sent!</center>";

?>

PeteM

8:13 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Ah, but I've got the text in a variable.

taylanpince

8:17 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



hello there,

are you sure you are using \r\n correctly? that's what i use all the time, and i haven't had any problems with it. an example follows:

<?php

$mail = "Dear ".$username.",\r\n\r\n";
$mail .= "Welcome to our web site.\r\n\r\n";
$mail .= "Web Site Team";

mail($usermail, "Welcome", $mail, "From: me@me.com\r\nReturn-Path: me@me.com")

?>

PeteM

8:33 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



This is what I've got....

$message = $message.'\r\n'.$renewal_url;

and it generates....

Click here to renew it\r\nhttp://wwWebmasterWorldebsite.com

Thanks, Pete

taylanpince

8:56 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



hmm i think the problem is with the single quotes. in php, it is always a good idea to go with the double quotes. i don't have time to run a test right now, but try it like this:

$message .= "\r\n".$url;

hope it helps.

cheers,
taylan

PeteM

9:26 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Thanks, I'll give it a go.

PeteM

9:34 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Yep, works perfectly with double quotes.

Thanks, Pete

coopster

3:22 am on Nov 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yep, that was exactly your issue, PeteM. Nice catch, taylanpince and welcome to WebmasterWorld.

More reading on the subject: Strings [php.net]