2016-07-05 1 views
0

자습서 사용 다음 PHPMailer PHP 파일을 붙여 넣은 후 다음 HTML 양식을 작성했습니다. 그러나 보내기 후 "메시지를 보낼 수 없습니다 .Mailer 오류 : 메시지 본문이 비어 있습니다."라는 오류 메시지가 나타납니다. 도와주세요. 여기 PHPMailer body message 빈 오류

<?php 
require 'phpmailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        

$mail->isSMTP();          
$mail->Host = 'smtp.gmail.com'; 
$mail->SMTPAuth = true;        
$mail->Username = '[email protected]';     
$mail->Password = 'xxx';       
$mail->SMTPSecure = 'tls';        
$mail->Port = 587;          

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  
$mail->addReplyTo('[email protected]', 'Information'); 

$mail->addAttachment('/var/tmp/file.tar.gz');   
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');  
$mail->isHTML(true);         



$mail->Subject = 'Here is the subject'; 
$mail->From = $email; 
$mail->FromName = $name; 
$mail->Body = $message; 



if(!$mail->send()) { 
echo 'Message could not be sent.'; 
echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
echo 'Message has been sent'; 
} 

?> 

<form name="contactform" method="post" action="email.php"> 

    <div class="input-text-container clear"> 
    <input type="text" name="name" id="name" placeholder="Your Name" 
    class="input-text input-text-left"> 

    <input type="text" name="email" id="email" placeholder="Your E-mail" 
    class="input-text input-text-right"> 
    </div> 

    <textarea type="text" name="message" id="message" placeholder="Your  
    Message" class="textarea"></textarea> 

    <button type="submit" value="submit Form" class="submit">SUBMIT</button> 

</form> 

답변

1

스크립트가 요청 매개 변수가 전역 변수로 사용할 수있는에 의존하는 것처럼 보이는 형태이다. 그러나 이것은 매우 드문 (그리고 안전하지 않은) 관행입니다.

$message 대신 $_POST['message']을 사용하고 메시지 본문에 양식의 데이터가 있어야합니다. 다른 매개 변수에 대해서도 동일하게 수행하십시오.

+0

감사합니다. 모든 매개 변수에 대해 수행 했으므로 이제는 본문과 이름을 모두 볼 수 있지만 응답을위한 전자 메일은 어디에도 나타나지 않습니다.이 부분이 어떻게 수정 될 수 있는지 알고 있습니까? – Huselius

+0

현재는 속성 ('From','FromName')과 그것들을 설정하는 메소드 ('setFrom()')를 모두 사용합니다. 하나는 다른 주소를 덮어 쓰므로'from @ example.com' 주소는 더 이상 전자 메일에 나타나지 않습니다. –

+0

내 혼란에 죄송합니다. [email protected]은 양식으로 작성된 전자 메일을 알아야하기 때문에 필자는 전혀 필요하지 않은 것 같습니다. setFrom()을 삭제해도 여전히 ID "이메일"인 입력란에 작성된 전자 메일이 표시되지 않습니다 – Huselius