Tim Aych
Tim Aych

Reputation: 1365

PEAR Mail function - Problems with line breaks

I'm trying to send a simple text-only email with an attachment. Everything's working great so far aside from line-breaks being properly inserted. Code:

$text = 'Product Name: '.$exchange;
    $text .= '\nCompany Name: '.$company_name;
    $text .= '\nContact Name: '.$contact_name;
    $text .= '\nContact Email: '.$contact_email;
    $text .= '\nWebsite: '.$website;
    $text .= '\nDescription: '.$description;


$subject =  "I'm interested in signing up.";

$visitor_email = '[email protected]';

$crlf = "\n";

$message = new Mail_mime($crlf);

$message->setTXTBody($text);

$message->addAttachment($path_of_uploaded_file);

$body = $message->get();

$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);

$headers = $message->headers($extraheaders);

$mail = Mail::factory("mail");

$mail->send('[email protected]', $headers, $body);

 if (PEAR::isError($mail)) {
    echo($mail->getMessage());
}
else {
    echo("Your request has been submitted successfully. Thanks!");
    header("Location: home.html");
    die();
}

} else {
  // submitNoLogo();
    echo 'not sent';
}

In the email, all the text is on one line with \n's between where I wanted the lines. Anyone know what might be up? Thanks.

Upvotes: 0

Views: 973

Answers (2)

Ante Barić
Ante Barić

Reputation: 9

You should put \r\n not just /n, also put them on the end not beginning

$text .= 'Company Name: '.$company_name.'\r\n';
$text .= 'Contact Name: '.$contact_name.'\r\n';
$text .= 'Contact Email: '.$contact_email.'\r\n';
$text .= 'Website: '.$website.'\r\n';
$text .= 'Description: '.$description.'\r\n';

\r\n are end of line characters for Windows systems and \n is the end of line character for UNIX systems.

Upvotes: 0

donald123
donald123

Reputation: 5749

put your $text in double quot instead of single

 <?php
     $text = 'Product Name: '.$exchange;
     $text .= "\nCompany Name: ".$company_name;
     ....

Upvotes: 1

Related Questions