|  首頁
說明

GoDaddy 說明

噠啦噠啦噠...計算中...計算中...啟動序列 42...
啵啵嗶嗶啵… 機器人自動化中… 此網頁是經由機器人自動翻譯成您的本地語言。某些翻譯可能還不盡完善,我們需要您的幫助!使用頁面底部的按鈕告訴我們本文是否有幫助。 前往英語版本

建立 PHP 表單郵件程式

Linux 專屬或虛擬專用伺服器 (VPS) 上使用 PHP 的表單郵件程式,建立網頁表單 html 連結到 PHP 檔案和上傳您的伺服器。範例指令碼會看到下面。

如需詳細資訊上設定郵件伺服器查看轉送郵件伺服器設定我的專屬伺服器為何?

<>

// $mail_to and $mail_from must be set.

$mail_to = ''; // Who is the E-Mail going to?
$mail_from = ''; // Where does the E-Mail appear to be from?

// OPTIONAL SETTING
$redirect_url = ''; // Example: http://domain.com/thankyou.html - must be a FULL URL.

############################
# DO NOT EDIT BELOW THIS #
############################

// Fail if _POST and _GET are empty. Nothing to process.
if(count($_POST) == 0 AND count($_GET) == 0):
echo 'This form handler does nothing if visited directly. You must submit form data to this script.';
exit;
endif;

// Fail if $mail_to or $mail_from are not set.
if(empty($mail_to) OR empty($mail_from)):
echo 'You must edit this script and set the appropriate values for $mail_to and $mail_from.';
exit;
endif;

// Set $fields to whichever method is being used.
$fields = (count($_POST) > 0 ) ? $_POST : $_GET;

$message_body = "Form Submission \n\n";

foreach ($fields as $field => $value):
switch(strtolower($field)):
case 'redirect':
$redirect = $value;
break;
case 'subject':
$subject = $value;
break;
endswitch;
if (strtolower($field) != 'redirect' AND strtolower($field) != 'submit' AND strtolower($field) != 'subject'):
$message_body .= strtoupper($field) . ": " . $value . "\r\n";
endif;
endforeach;

// Set the redirect URL from the form (if set). $host_url is a default action if $redirect isn't set
$redirect = (empty($redirect_url)) ? $redirect : $redirect_url;
$host_url = $_SERVER['HTTP_HOST'];

// Set the message subject based upon a subject field being set or not.

$message_subject = (!empty($subject)) ? $subject : 'Message from '.$_SERVER['HTTP_HOST'];

$headers = 'From: ' . $mail_from. "\r\n" .
'Reply-To: ' . $mail_from . "\r\n" .
'X-Mailer: PHP/' . phpversion();

// Remove potentially injected headers from the body

if (!mail($mail_to, $message_subject, $message_body, $headers)):
echo "Message Send Failed.";
endif;

if(empty($redirect)):
header("Location: http://{$host_url}");
else:
header("Location: {$redirect}");
endif;
?>


這篇文章有用嗎?
感謝您提供意見。 若要與客戶服務代表聯絡,請撥打支援中心電話號碼,或使用上方的對話選項。
很高興能幫上忙! 還有什麼可幫您的嗎?
很抱歉有這種情形。 請告訴我們您不了解的部分,或解決方案無法解決您問題的原因。