5 Replies - 547 Views - Last Post: 13 May 2013 - 12:26 PM Rate Topic: -----

#1 charliebada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 08-May 13

Email in php: creating line breaks in a string

Posted 13 May 2013 - 11:04 AM

Hello i have tried a few different methods of creaking a line break in the email message. I cannot figure out why the sent email is received as all on one line though.

	$subject = "Order Confirmation";
	$message = "THANK YOU, for your purchase. Here is your Order ID: $Orderid \r\n    // here is my issue
					***If you did not place an order with CorePCTechs please contact us immediately";
	$headers  = 'From: corepctechs@gmail.com' . "\r\n" .
           'Reply-To: corepctechs@gmail.com' . "\r\n" .
           'MIME-Version: 1.0' . "\r\n" .
           'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();



Is This A Good Question/Topic? 0
  • +

Replies To: Email in php: creating line breaks in a string

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3530
  • View blog
  • Posts: 10,179
  • Joined: 08-June 10

Re: Email in php: creating line breaks in a string

Posted 13 May 2013 - 11:09 AM

that’s simple. you define the email to be a HTML email and in HTML the line breaks (as well as any other whitespace character) are displayed as a single space.
Was This Post Helpful? 2
  • +
  • -

#3 charliebada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 08-May 13

Re: Email in php: creating line breaks in a string

Posted 13 May 2013 - 12:13 PM

Ok i changed it to html and now the line breaks work fine but my $orderid doesnt show in the email.

        $subject = "Order Confirmation";
	$message =  '<html>
			<body>
			 <p>THANK YOU for your purchase. Here is your Order ID: $Orderid<br> //this doesnt work
		         ***If you did not place an order with CorePCTechs please contact us                                                    immediately***
		        </p>
		       </body>
	            </html>';
		$headers = 'From: corepctechs@gmail.com' . "\r\n" .
            'Reply-To: corepctechs@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();


Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3530
  • View blog
  • Posts: 10,179
  • Joined: 08-June 10

Re: Email in php: creating line breaks in a string

Posted 13 May 2013 - 12:18 PM

why should it? single quotes strings are not parsed for variables.
Was This Post Helpful? 2
  • +
  • -

#5 charliebada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 08-May 13

Re: Email in php: creating line breaks in a string

Posted 13 May 2013 - 12:24 PM

Oh i see. so change the single quotes to double quotes. Works perfect now. thanks for pointing me in the right direction!
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3530
  • View blog
  • Posts: 10,179
  • Joined: 08-June 10

Re: Email in php: creating line breaks in a string

Posted 13 May 2013 - 12:26 PM

you could have changed the Content-Type in the first post to text/plain as well …

additionally, PHP strings can span several lines without problem. the HEREDOC syntax is also a convenient way to declare strings.

This post has been edited by Dormilich: 13 May 2013 - 12:28 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1