[英]Why this submit form “check list” data doesn't send to email with PHP?
[英]How to send form check list data with PHP to a specific email
我真的很難找到一種方法將清單數據發送到電子郵件,更不用說用戶輸入電子郵件了! 我試過跟隨並應用其他類似問題的答案,但仍無濟於事。
這是我的PHP到目前為止,雖然我很困惑。
<?php
//Check for POST
if (isset($_REQUEST['email'])){
//All your inputs
$expecting = array('checkbox1','checkbox2','checkbox3','checkbox4' ,'checkbox5');
//Start building your email
$email_content = '';
foreach($expecting as $input){
//Is checkbox?
if(substr($input,0,8)=='checkbox'){
$email_content .= ucfirst($input).':'.(isset($_POST[$input]) && $_POST[$input] == 'on' ? 'True' : 'False'.'<br />');
}else{
$email_content .= ucfirst($input).':'.(!empty($_POST[$input]) ? $_POST[$input] : 'Unknown').'<br />';
}
}
print_r($email_content);
if(mail('$email', 'packing list', wordwrap($email_content))){
//mail sent
}else{
//mail failed 2 send
}
}
?>
這是我的HTML
<form name="emailform" method="post" action="send-list.php">
<div data-role="fieldcontain">
<label for='name'><h3>Festival name:</h3> </label>
<input type="text" name="name">
<h3>
Essentials
</h3>
<fieldset data-role="controlgroup" data-type="vertical">
<legend>
</legend>
<input name="checkbox1" id="checkbox1" type="checkbox" />
<label for="checkbox1">
Tickets
</label>
<input name="checkbox2" id="checkbox2" type="checkbox" />
<label for="checkbox2">
Parking pass
</label>
<input name="checkbox3" id="checkbox3" type="checkbox" />
<label for="checkbox3">
Directions
</label>
<input name="checkbox4" id="checkbox4" type="checkbox" />
<label for="checkbox4">
Cash & Cards
</label>
<input name="checkbox5" id="checkbox5" type="checkbox" />
<label for="checkbox5">
Keys
</label>
</fieldset>
Email: <input name='email' type='text'><br>
<input type="submit" value="Send">
如果我能將復選框發送到電子郵件,我會很高興,我希望能夠找到如何將信息發送到用戶輸入電子郵件。
你做的大部分是正確的,但是你的代碼檢查復選框的值是否為“on”...但是從不在表單中設置該值:
<input name="checkbox5" id="checkbox5" type="checkbox" value="on" />
^^^^^^^^^^
這也是一個語法錯誤:
if(mail('$email', 'packing list', wordwrap($email_content))){
^-- ^--
單引號字符串不插入變量。 因此,您嘗試向名為$email
的帳戶$email
,而不是$ email變量中的任何地址。
嘗試
if(mail($email, 'packing list', wordwrap($email_content))){
相反(注意缺少報價)。
$email
變量未定義。
把這個:
$email = $_REQUEST['email'];
在mail
功能調用之前,使用mail($email, ...
讓它工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.