Issues with \n in mail
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
formating email messages to be sent via mail()
Hello,
I am trying to develop a template to format my email messages which will be sent via mail()
i am using the following syntax to send my mail
mail($to_email,$subject,$message,'From: $name <$fromemail>');
how ever my messages come out like this :-
The following information was submitted :- \r\nDomain : apex-solutions.com\r\nRegister for 2\r\n\r\nTotal Amount to be paid : \r\n\r\nContact Information :- \r\nFirst Name : kendall\r\nLast Name : arneaud\r\nCompany : Apex Solutions\r\nAddress : #1 A Brieves Road., Brieves Road, Maraval\r\nWork Phone : 0000000000\r\nHome Phone : 0000000000\r\nFax : 0000000000\r\nEmail : accounts@thissite.com\r\n
what is being done wrong here
I am trying to develop a template to format my email messages which will be sent via mail()
i am using the following syntax to send my mail
mail($to_email,$subject,$message,'From: $name <$fromemail>');
how ever my messages come out like this :-
The following information was submitted :- \r\nDomain : apex-solutions.com\r\nRegister for 2\r\n\r\nTotal Amount to be paid : \r\n\r\nContact Information :- \r\nFirst Name : kendall\r\nLast Name : arneaud\r\nCompany : Apex Solutions\r\nAddress : #1 A Brieves Road., Brieves Road, Maraval\r\nWork Phone : 0000000000\r\nHome Phone : 0000000000\r\nFax : 0000000000\r\nEmail : accounts@thissite.com\r\n
what is being done wrong here
might be easier to use a class like http://devscripts.com/viewscript.php?sId=1351
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
formating email messages to be sent via mail()
Yes,
Propbably it would but all i want is a text formated email to be sent. To me i am doing everything by the book as simple as i can put it actually. i see no reason why it is ignoring the '\r\n' characters.
Was i suppose to add additional headers?
Kendall

Propbably it would but all i want is a text formated email to be sent. To me i am doing everything by the book as simple as i can put it actually. i see no reason why it is ignoring the '\r\n' characters.
Was i suppose to add additional headers?
Kendall
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Have you made sure that you've got all the headers from the example in the mail() function manual page?
http://www.php.net/manual/en/function.mail.php
You may wish to uncomment this line:
Mac
http://www.php.net/manual/en/function.mail.php
You may wish to uncomment this line:
Code: Select all
//$headers .= "MIME-Version: 1.0\r\n";- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
formating email messages to be sent via mail()
ok ok
not even that is working
listen i dont want to have the email in an html format but just a neat text format with the normal line breaks and carraige returns which doesnt seem to be taking affect in my emails
here is the code im using
<?php
$to_email = 'email@email.com';
$from_email = $_POST['Email'];
$from_name = $_POST['First_Name']." ".$_POST['Last_Name'];
$subject = 'Application for '.$_POST["Form"];
$headers = "MIME-Version: 1.0\r\n ";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from_name." <".$from_email.">";
$body_msg = 'The following information was submitted :- \n \n ';
$body_msg .= 'Domain : '.$_POST['domain'].'\n \n ';
if(($_POST['Form'] == 'Domain Registration') || ($_POST['Form'] == 'Domain Renewal')){
$body_msg .=
'Register for '.$_POST['years'].'\n \n ';
}
if(($_POST['Form'] == 'Hosting') || ($_POST['host'] == true)){
$body_msg .=
$_POST['status'].' Hosting \n \n on an '.$_POST['Package'].' Host Server Package \n \n '.'Server User Name : '.$_POST['User'].'\n \n '.'Server Password : '.$_POST['Pass'].'\n \n '.'with the following specifications :- \n \n '.$_POST['details'].'Payment is due for '.$_POST['Months'].' Month(s) on approval \n \n ';
}
if($_POST['Form'] == 'Search Engine Registration'){
$body_msg .='Register with '.$_POST['Registrant'].' for 1 year \n \n '.'Web Page Title : '.$_POST['Title'].'\n \n '.'Keywords :- \n \n '.$_POST['Keywords'].'\n \n '.'Description :- \n \n '.$_POST['Description'].'\n \n ';
}
$body_msg .= 'Total Amount to be paid : '.$_POST['Amount'].'\n \n '.'Contact Information :- \n \n '.'First Name : '.$_POST['First_Name'].'\n \n '.'Last Name : '.$_POST['Last_Name'].'\n \n '.'Company : '.$_POST['Company'].'\n \n '.'Address : '.$_POST['Address1'].', '.$_POST['Address2'].', '.$_POST['City'].'\n \n '.'Work Phone : '.$_POST['Work_Phone'].'\n \n '.'Home Phone : '.$_POST['Home_Phone'].'\n \n '.'Fax : '.$_POST['Fax'].'\n \n '.'Email : '.$_POST['Email'].'\n \n ';
mail($to_email,$subject,$body_msg,$headers);
?>
here's the results
The following information was submitted :- \n \n Domain : apex.com\n \n Register with SRCHENGINK for 1 year \n \n Web Page Title : The APex\n \n Keywords :- \n \n some. key, words,\n \n Description :- \n \n the description used in this session dont put it anywhere else\n \n Total Amount to be paid : \n \n Contact Information :- \n \n First Name : Kenda\n \n Last Name : Arnead\n \n Company : Apex Solutions\n \n Address : #1 A, Brieves Rd., Maraval\n \n Work Phone : 0000000000\n \n Home Phone : 0000000000\n \n Fax : 8686284677\n \n Email : kendall@apex-solutions.com\n \n
ok but heres what i want
The following information was submitted :-
Domain : apex.com
Register with SRCHENGINK for 1 year
Web Page Title : The APex
Keywords :-
some. key, words,
Description :-
the description used in this session dont put it anywhere else
Total Amount to be paid :
Contact Information :-
First Name : Kenda
Last Name : Arnead
Company : Apex Sol
Address : #1 A, Brieves Rd., Maraval
Work Phone : 0000000000
Home Phone : 0000000000
Fax : 8686284677
Email : kendall@email.com
Now this is to simple for me to screw up yet....TAAAADAAAAAAAa i have i am really really trying to see my mistake but what is it im suppose to look for in this instance???
Kendall

not even that is working
listen i dont want to have the email in an html format but just a neat text format with the normal line breaks and carraige returns which doesnt seem to be taking affect in my emails
here is the code im using
<?php
$to_email = 'email@email.com';
$from_email = $_POST['Email'];
$from_name = $_POST['First_Name']." ".$_POST['Last_Name'];
$subject = 'Application for '.$_POST["Form"];
$headers = "MIME-Version: 1.0\r\n ";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from_name." <".$from_email.">";
$body_msg = 'The following information was submitted :- \n \n ';
$body_msg .= 'Domain : '.$_POST['domain'].'\n \n ';
if(($_POST['Form'] == 'Domain Registration') || ($_POST['Form'] == 'Domain Renewal')){
$body_msg .=
'Register for '.$_POST['years'].'\n \n ';
}
if(($_POST['Form'] == 'Hosting') || ($_POST['host'] == true)){
$body_msg .=
$_POST['status'].' Hosting \n \n on an '.$_POST['Package'].' Host Server Package \n \n '.'Server User Name : '.$_POST['User'].'\n \n '.'Server Password : '.$_POST['Pass'].'\n \n '.'with the following specifications :- \n \n '.$_POST['details'].'Payment is due for '.$_POST['Months'].' Month(s) on approval \n \n ';
}
if($_POST['Form'] == 'Search Engine Registration'){
$body_msg .='Register with '.$_POST['Registrant'].' for 1 year \n \n '.'Web Page Title : '.$_POST['Title'].'\n \n '.'Keywords :- \n \n '.$_POST['Keywords'].'\n \n '.'Description :- \n \n '.$_POST['Description'].'\n \n ';
}
$body_msg .= 'Total Amount to be paid : '.$_POST['Amount'].'\n \n '.'Contact Information :- \n \n '.'First Name : '.$_POST['First_Name'].'\n \n '.'Last Name : '.$_POST['Last_Name'].'\n \n '.'Company : '.$_POST['Company'].'\n \n '.'Address : '.$_POST['Address1'].', '.$_POST['Address2'].', '.$_POST['City'].'\n \n '.'Work Phone : '.$_POST['Work_Phone'].'\n \n '.'Home Phone : '.$_POST['Home_Phone'].'\n \n '.'Fax : '.$_POST['Fax'].'\n \n '.'Email : '.$_POST['Email'].'\n \n ';
mail($to_email,$subject,$body_msg,$headers);
?>
here's the results
The following information was submitted :- \n \n Domain : apex.com\n \n Register with SRCHENGINK for 1 year \n \n Web Page Title : The APex\n \n Keywords :- \n \n some. key, words,\n \n Description :- \n \n the description used in this session dont put it anywhere else\n \n Total Amount to be paid : \n \n Contact Information :- \n \n First Name : Kenda\n \n Last Name : Arnead\n \n Company : Apex Solutions\n \n Address : #1 A, Brieves Rd., Maraval\n \n Work Phone : 0000000000\n \n Home Phone : 0000000000\n \n Fax : 8686284677\n \n Email : kendall@apex-solutions.com\n \n
ok but heres what i want
The following information was submitted :-
Domain : apex.com
Register with SRCHENGINK for 1 year
Web Page Title : The APex
Keywords :-
some. key, words,
Description :-
the description used in this session dont put it anywhere else
Total Amount to be paid :
Contact Information :-
First Name : Kenda
Last Name : Arnead
Company : Apex Sol
Address : #1 A, Brieves Rd., Maraval
Work Phone : 0000000000
Home Phone : 0000000000
Fax : 8686284677
Email : kendall@email.com
Now this is to simple for me to screw up yet....TAAAADAAAAAAAa i have i am really really trying to see my mistake but what is it im suppose to look for in this instance???
Kendall
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
This isn't working because you've got the \n stuff in single quotes which PHP doesn't parse and so you end up with \n being printed literally instead of being interpreted as new lines - it's as if you had escaped them all and had \\n instead of \n.
You'd have to change something like:
to
Alternatively bang it all into double quotes.
Mac
You'd have to change something like:
Code: Select all
$body_msg .='Register with '.$_POST['Registrant'].' for 1 year \n \n '.'Web Page Title : '.$_POST['Title'].'\n \n '.'Keywords :- \n \n '.$_POST['Keywords'].'\n \n '.'Description :- \n \n '.$_POST['Description'].'\n \n ';Code: Select all
$body_msg .= 'Register with '.$_POST['Registrant'].' for 1 year '."\n\n".'Web Page Title : '.$_POST['Title']."\n\n".'Keywords :- '."\n\n".$_POST['Keywords']."\n\n".'Description :- '."\n\n".$_POST['Description']."\n\n";Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
PS. I didn't realise that you had hijacked someone else's thread for this and thought their code was your code. In future please start your own topics instead of replying to someone else's thread with questions on your own code and totally disregard everything I said about headers, it doesn't apply to you.
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
formating email messages to be sent via mail()
ARRRRRRRRRRRRGH!
i dont believe that it was as simple as dat
geeeez
that was F&@! up anyway
thanks for the enlightenment
OH i didnt no i was highjacking. thought i started a new thread. i think i was searching tru to find an answer and stumbled on his thread. i think your search methods are a bit too generalised. i dunno im frustrated im going to have a drink
Thanks
Kendall
i dont believe that it was as simple as dat
geeeez
that was F&@! up anyway
thanks for the enlightenment
OH i didnt no i was highjacking. thought i started a new thread. i think i was searching tru to find an answer and stumbled on his thread. i think your search methods are a bit too generalised. i dunno im frustrated im going to have a drink
Thanks
Kendall