2013-04-22 2 views
1

나는 메일을 보내기 위해 PHPMailer를 사용하고 있으며 메일 본문에 대한 텍스트 영역을 가지고 있습니다. 텍스트를 쓸 때 나는 새로운 라인을 필요로하지만 새로운 라인이 필요할 때 작동하지 않습니다. 텍스트가 풍부한 메일은 여전히 ​​한 줄만 표시됩니다. 나는 아래와 같은 PHP 코드를 가지고 :Textarea PHP를 사용하여 이메일을 전송하기위한 새로운 행

<?php 

if(isset($_POST['submit'])){ 
    require_once('class.phpmailer.php');   
    $mail = new PHPMailer(); // defaults to using php "mail()" 
    $body = str_replace ('<br>' , '\r\n', $_POST['about']); // $_POST['about'] is the value text take from the body text area of mail 
    //$body = $_POST['about']; 
    $from = $_POST['from'];  
    $mail->AddReplyTo($from,$from);  
    $mail->SetFrom($from, $from);  
    $mail->AddReplyTo($from,$from); 

    $address = $_POST['email']; 
    $mail->AddAddress($address, $address);  
    $mail->Subject = $_POST['subject']; 

    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test  
    $mail->MsgHTML($body);  
    if(!$mail->Send()) { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
     echo "Message envoy&eacute;!"; 
    } 
} 
?> 

사람이하시기 바랍니다, 감사를 해결하는 데 도움이.

+0

'$ mail-> AltBody = "메시지를 보려면 HTML 호환 전자 메일 뷰어를 사용하십시오!"- 강하게 ** 실제로 전자 메일 소프트웨어를 변경하기위한 지침 대신 일반 텍스트 대신 사용하는 것이 좋습니다. 당신의 전자 우편은 전자 우편 클라이언트를 읽기 위하여 그것을 바꾸는 사람들을 위해 충분히 중요하지 않게 확률이 낮다! 이 양식의 – Quentin

답변

2

PHP의 nl2br() 함수를 확인하십시오. 나는 이것이 당신이 찾고있는 무엇을 믿는다, 나는 그것이

$body = str_replace ('\r\n' , '<br>' , $_POST['about']); 

\r\n 단순히 <br>

1

$body = nl2br ($_POST['about']); 

그리고이 코스를 저장하고 있습니다. 오 MySQL 데이터베이스, 여기

$body = mysql_real_escape_string (nl2br ($_POST['about'])); 

이 있습니다, 그 사용하므로, $body = nl2br (mysql_real_escape_string ($_POST['about']));이 작동하지 않습니다.

+1

은 그다지 유용하지 않습니다. 후손에 대한 설명을 추가하는 것을 고려하십시오. –

0

왜 이렇게 힘들게해야합니까?

//here is the pull from the form 
$your_form_text = $_POST['your_form_text']; 

//line 1 fixes the line breaks - line 2 the slashes 
$your_form_text = nl2br($your_form_text); 
$your_form_text = stripslashes($your_form_text); 

//email away 
$message = "Comments: $your_form_text"; 
mail("[email protected]", "Website Form Submission", $message, $headers); 

분명히 헤더가 필요하며 더 많은 입력란이 있어야하지만 텍스트 영역입니다.

관련 문제