0
我有一個相當基本的PHP表單,它在同一頁上提交它被稱爲「registration.php」。我把它設置爲收集表單數據,將它存儲在$ to,$ subject和$ body變量中,然後我調用mail()方法向我發送一封電子郵件。如何發送回覆電子郵件給用戶表單提交PHP
請參見下面的代碼(!不要擔心有科曼直到一個問題!):
<?php
ob_start(); //output buffering because I like it.
if (isset($_POST['submit'])) {
// Process the form
$message = "Thank you for registering! We will respond to your request shortly";
$name = $_POST['name'];
$email = $_POST['email'];
$address = $_POST['address'];
$comments = $_POST['userComment'];
$date = gmdate("M d Y");
$to = "[email protected]";
$subject = "Registration Submission";
$body = " Date: $date \n Registrant Name/Name's: $name \n Registrant E-mail: $email \n \n User Comments: \n $comments \n \n";
mail($to,$subject,$body);
}
?>
<form id="contactForm" name="contactForm" action="registration.php" method="post">
<table>
<tr>
<td><label for="name"><strong>Registrant Name/Names</strong></label></td>
<td><input required='required' type="text" id="name" name="name" /></td>
</tr>
<tr>
<td><label for="email"><strong>Registrant E-mail</strong></label></td>
<td><input required='required' type="email" maxlength="40" id="email" name="email" /></td>
</tr>
<tr>
<td><label for="subject"><strong>Registrant Address</strong></label></td>
<td><input required='required' type="text" maxlength="100" id="address" name="address" /></td>
</tr>
<tr>
<td>Message:</td>
<td> </td>
</tr>
<tr>
<td id="textAreaInput" colspan="2"><textarea rows="3" id="userComment" name="userComment" placeholder="Let us know your thoughts!"></textarea></td>
</tr>
</table>
<br />
<button type="submit" name="submit" id="submit">Submit</button>
</form>
我想知道的是我可以發送一個定製響應電子郵件到用戶只用php收集了一封包含自定義消息的$ email?我可以通過mail()方法發送其他變量嗎?像$ to2,$ subject2,$ body2或者必須將它們命名爲$ to,$ subject & $ body何時通過?
我使用PHPMailer的在這裏找到一個有效的解決方案:
https://github.com/PHPMailer/PHPMailer
我只是好奇,以weither或不存在使用PHP,不會依賴於所需的庫一個簡單的過程。
變量可以任意取名 – dbinns66
哦我只是覺得難過完全傻了,現在即可。所以我可以在郵件中聲明$ to2,$ subject2,$ body2($ to2,$ subject2,$ body2)並放入用戶信息中。 neato生病了吧 – Eolis
編程的最有趣和最具教育意義的部分是試驗;-)享受! – dbinns66