0
使用教程我粘貼並填寫了以下PHPMailer php文件並製作了以下html表單。然而,在發送錯誤後出現「郵件無法發送。郵件錯誤:郵件正文爲空」。請幫忙。PHPMailer正文消息空錯誤
<?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>
謝謝,我爲它做了所有參數,現在我可以看到它們的正文和名稱,但是響應的電子郵件並沒有出現在任何地方,你知道這個方面可能如何解決嗎? – Huselius
當前,您使用兩個屬性('From','FromName')和設置它們的方法('setFrom()')。一個會覆蓋另一個,所以'from @ example.com'的地址不會再出現在您的電子郵件中。 –
抱歉我的困惑。來自@example.com,似乎我根本不需要,因爲我需要知道寫在表單中的電子郵件。如果我刪除了setFrom(),它仍然不會顯示電子郵件,該電子郵件已寫入ID爲「email」的輸入單元中 – Huselius