![](/img/trans.png)
[英]Send email with PHP from html form on submit with the same script
[英]Send email with PHP from html form on submit
每當我測試此代碼時,它總是失敗,有人可以幫忙嗎?
<?php if(isset($_POST['submit'])){
$to = "<<<___myEmail___>>>";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Contact Form: LewisDerbyshire.co.uk";
$subject2 = "Copy of your form submission : LewisDerbyshire.co.uk";
$message = $name . "wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$IP = "Senders IP :" . [REMOTE_ADDR];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$IP,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $name . ", I will contact you shortly.";
if ($sent) {
$result = 'Thank you,' . $name . 'Your message has been sent.';
} } else {
$result = 'Sorry' . $name . ', there was a problem.'; } ?>
我也有<?php echo $result; ?>
<?php echo $result; ?>
在我的桌子旁邊,但如何停止顯示任何人單擊之前提交的消息。
乍一看,我發現您在嘗試獲取遠程IP的行中缺少變量名。 嘗試使用$_SERVER['REMOTE_ADDR']
而不是[REMOTE_ADDR]
$_SERVER['REMOTE_ADDR']
。
如果此修復程序后不起作用,請發布一些錯誤消息,以更輕松地為您提供幫助。
您錯過了輸入代碼,所以我嘗試編寫一個,希望對您有所幫助。
首先,如果標記太早,則關閉。 其次,未定義變量$ sent。 第三,我的$ sent變量還不清楚...
<form method="POST">
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="message" />
<input type="submit" name="submit" />
</form>
<?php if (isset($_POST['submit'])) {
$to = "Your mail";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Contact Form: LewisDerbyshire.co.uk";
$subject2 = "Copy of your form submission : LewisDerbyshire.co.uk";
$message = $name . "wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$IP = "Senders IP :" . $_SERVER["REMOTE_ADDR"];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
$sent = mail($to, $subject, $message, $IP, $headers);
mail($from, $subject2, $message2, $headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $name . ", I will contact you shortly.<br/>";
if ($sent) {
$result = 'Thank you,' . $name . ' Your message has been sent.';
echo $result;
} else {
$result = 'Sorry' . $name . ', there was a problem.';
echo $result;
}
} ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.