我試圖讓一個應用程序在單擊按鈕時發送電子郵件。我試圖使用isset函數來做到這一點。但是我的代碼工作不正常。我如何解決它?下面如何在點擊提交按鈕時觸發郵件功能
演示:
<!-- <button name="sendemail">send</button> -->
<input type="submit" value="send"/>
<?php
if(isset($_POST['Submit'])){
?>
<?php
// multiple recipients
// $to = '[email protected]' . ', ';
// $to .= '[email protected]';
$to="[email protected]";
// subject
$subject = 'test01';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
你會得到什麼錯誤? – Fjodr
提交按鈕沒有'name'屬性,並且是放置在表單中的按鈕(意思是它首先通過POST發送)?另外,這個'?> <?php'實際上只是浪費空間。您還應該檢查郵件是否實際發送,您目前沒有做。 – Qirel
@Qirel和PHP結束標記?>是一個普通的錯誤 –