|  主页
帮助

GoDaddy 帮助

啵啵哔哔啵… 正在计算…...正在计算...…启动序列 42...…
啵啵哔哔啵… 机器人自动化中… 此网页是经由机器人自动翻译成您的本地语言。某些翻译可能还不尽完善,我们需要您的帮助!使用页面底部的按钮告诉我们本文是否有帮助。 转至英文版本

创建 PHP Form Mailer

要使用 Linux 专属或虚拟专享服务器 (VPS) 上的 PHP form mailer,创建一个 Web 表单在 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;
?>


本文是否有帮助?
感谢您的反馈。 要咨询客户服务代表,请使用上面的客户支持电话号码或聊天选项。
很高兴我们能有所助益! 我们还可以为您做些什么?
我们对此深感抱歉。 请告诉我们,什么问题令您费解,或者解决方案为何未能解决您的问题。