當用戶提交表單時,我正在使用PHPMailer將HTML表單中的表單數據郵寄到HTML表單中。在電子郵件正文中引用fullName
時會出現語法錯誤。如果沒有引號,則不顯示錯誤。我是PHP的新手,並且我不確定如何從PHP內部引用HTML表單,當我聲明一組代碼是HTML時。這裏是我的代碼:在PHP中引用表單數據時引發語法錯誤
注意:我正在使用Dreamweaver對此進行編碼,有時語法更正不正確,但我想確保在忽略它並編寫整個文檔之前。
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';
$mail->From="[email protected]";
$mail->FromName="My site's mailer";
$mail->Sender="[email protected]";
$mail->AddAddress("[email protected]");
$mail->Subject = "Test 1";
$mail->IsHTML(true);
$mail->Body = "
<h1>Graphics Request</h1>
Name: $_POST['fullName']<br />
";
$mail->AltBody="This is text only alternative body.";
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
echo "Letter is sent";
}
?>
在雙引號字符串中加入{{_POST ['fullName']}' –