[SOLVED] New line in basic e-mail..

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
ddj
Forum Newbie
Posts: 2
Joined: Tue May 01, 2007 5:23 am

[SOLVED] New line in basic e-mail..

Post by ddj »

Hello, what's wrong with the code below? Why I get the body of the e-mail on a single line even if I used the new line char (\n\n) ? Any help would be appreciated... thank you!

Code: Select all

$message = new Swift_Message('Test', 'Hello,\n\nhow are you?');
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Don't use literal quotes.

Code: Select all

$message = new Swift_Message('Test', "Hello,\n\nhow are you?");
ddj
Forum Newbie
Posts: 2
Joined: Tue May 01, 2007 5:23 am

Post by ddj »

thanks a lot, it works (I spent 3 hours with this stupid thing..) :)
chazter6
Forum Newbie
Posts: 9
Joined: Thu Apr 12, 2007 1:38 pm

Post by chazter6 »

Am I missing something?

I am too trying to put blank lines but cant seem to get it working properly. My e-mail looks like this...

(Its one long line...no line breaks)
Here are your login details. Your password has been reset. Please change your TEMPORARY password once you have logged into the LNP system. Login: loginInfo Password: passwordInfo


I want it to look like this, with linebreaks for Login and Password info.

Here are your login details. Your password has been reset. Please change your TEMPORARY password once you have logged into the LNP system.
Login: loginInfo
Password: passwordInfo

Code: Select all

// SwiftMailer settings
$yourName='Administrator';
$yourEmail='webmaster@idomain.tld;
$subject='Your Temporary password';
$msg='Here are your login details. Your password has been reset.  Please change your TEMPORARY password once you have logged into the system.';

$messgeHTML = $msg."\n\n"."Login: ".$details['login']."\n\n"."Password: ".$details['password'];

$subjMsg = $subject;	  
	   
// Add the recipient
$name=$details['firstName'].' '.$details['lastName'];
$toAddress = $form->getSubmitValue('email');
				  
$swiftHtml = new Swift_Message_Part($messgeHTML, "text/html"); 						
	   
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("mail.domain.tld"));
	      		
//Create the message
$message =& new Swift_Message($subjMsg);
$message->attach($swiftHtml,"text/html");		
		
// Instantiate a repipient list
$recipients =& new Swift_RecipientList();
$recipients->addTo($toAddress, $name);		
		
//Now check if Swift actually sends it
if ($swift->send($message, new Swift_Address($toAddress, $name), $yourEmail)) {
echo 'success';
} else {
echo 'fail';
}
Thanks for your assistance!
dillion
Forum Commoner
Posts: 56
Joined: Thu Feb 15, 2007 8:32 am

Post by dillion »

\n\n is only good for plain text emails and in your case you are using HTML. So I would replace all instances of

Code: Select all

\n\n
with

Code: Select all

<br /><br />
chazter6
Forum Newbie
Posts: 9
Joined: Thu Apr 12, 2007 1:38 pm

Post by chazter6 »

dillion,
thanks for the response. You are absolutely correct. For some reason, I thought my e-mail client settings were set to TEXT, but I guess they were set to HTML instead. I should have thought of that.

Cheers!
Post Reply