[英]PHP: Getting the email from a form and sending it when a button is clicked
因此,我希望該站點發送2封電子郵件-給員工和客戶。 工作人員有一個預設的電子郵件,而客戶則必須將其寫在文本框(窗體)中。 我試圖得到客戶的郵件。
<form id='contact-info' method='post' novalidate class="form contact-info">
<div class="contact-info__field contact-info__field-mail">
<input type='email' name='user-mail' placeholder='Your email' class="form__mail">
</div>
<div class="contact-info__field contact-info__field-tel">
<input type='tel' name='user-tel' placeholder='Phone number' class="form__mail">
</div>
</form>
</div>
<div class="order">
<a href="Rezervare-final.html" name="button1" class="btn btn-md btn--warning btn--wide">Cumpara</a>
</div>
And here's the php right after the html.
<?php
if (isset($_POST['button1'])) {
$toclient = "Test client";
$tostaff = "Test staff";
$maile = $_POST['user-mail'];
$toclient = wordwrap($toclient, 70);
$tostaff = wordwrap($tostaff, 70);
mail($maile, 'My Subject', $toclient);
mail('example@yahoo.com', 'My Subject', $tostaff);
}
?>
我能夠收到員工電子郵件,但不能收到客戶電子郵件。 問題:為什么我不能收到客戶的電子郵件?
您沒有使用提交按鈕提交數據,因此無法獲得$_POST['user-mail']
值。
如果您使用類似的代碼,它應該可以工作
<form id='contact-info' method='post' class="form contact-info" action="" >
<div class="contact-info__field contact-info__field-mail">
<input type='email' name='user-mail' placeholder='Your email' class="form__mail">
</div>
<div class="contact-info__field contact-info__field-tel">
<input type='tel' name='user-tel' placeholder='Phone number' class="form__mail">
</div>
<input type='submit' name='button1' value="submit">
</form>
</div>
除非您不與我們共享某些javascript,否則該表單永遠不會提交; button1是Rezervare-final.html的鏈接
因此,您需要將鏈接替換為“ 提交”按鈕 :
<input value= "Cumpara" type = "submit"/>
要么
<button type="submit">Cumpara</button>
在您的處理腳本中,不要聽按鈕; 如果多數民眾贊成在唯一的必填字段,請監聽電子郵件字段:
if(isset($_POST['user-mail'])){
//process form/emails
}
試試這個.....文件名應該是Rezervare-final.php而不是Rezervare-final.html
<form id='contact-info' method='post' action="Rezervare-final.php" class="form contact-info">
<div class="contact-info__field contact-info__field-mail">
<input type='email' name='user-mail' placeholder='Your email' class="form__mail">
</div>
<div class="contact-info__field contact-info__field-tel">
<input type='tel' name='user-tel' placeholder='Phone number' class="form__mail">
</div>
</form>
</div>
<div class="order">
<input type='submit' name='button1' value="Cumpara" class="btn btn-md btn--warning btn--wide>
</div>
And here's the php right after the html.
<?php
if (isset($_POST['button1'])) {
$toclient = "Test client";
$tostaff = "Test staff";
$maile = $_POST['user-mail'];
$toclient = wordwrap($toclient, 70);
$tostaff = wordwrap($tostaff, 70);
mail($maile, 'My Subject', $toclient);
mail('example@yahoo.com', 'My Subject', $tostaff);
}
?>
<form id='contact-info' method='post' novalidate class="form contact-info">
<div class="contact-info__field contact-info__field-mail">
<input type='email' name='user-mail' placeholder='Your email' class="form__mail">
</div>
<div class="contact-info__field contact-info__field-tel">
<input type='tel' name='user-tel' placeholder='Phone number' class="form__mail">
<input type="submit" name="submit" class="submit">
</div>
</form>
<?php
if (isset($_POST['submit'])) {
$toclient = "Test client";
$tostaff = "Test staff";
$maile = $_POST['user-mail'];
$toclient = wordwrap($toclient, 70);
$tostaff = wordwrap($tostaff, 70);
mail($maile, 'My Subject', $toclient);
mail('example@yahoo.com', 'My Subject', $tostaff);
}
?>
試試這個,我確實相信您在您的php腳本中缺少一些標頭以及查看php手冊,希望它能起作用:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.