我试图这样做,如果电子邮件成功发送,$email
将获得$mail_to
的自动回复,最好包含HTML签名。
CODE:
<?php
$mail_to = 'REMOVED@EMAILERE.com';
// specify your email here //
$name = $_POST['name'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$message = $_POST['message'];
// Construct email subject
$subject = 'Enquiry Form Submission';
$body_message .= 'Stage Name: ' . $name . "\r\n";
$body_message .= 'E-mail Address: ' . $email . "\r\n";
$body_message .= 'Reason for Contacting: ' . $reason . "\r\n";
$body_message .= 'Message: ' . $message . "\r\n";
$body_message .= "IP Address: " . getUserIpAddr();
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){
?>
<script language="javascript" type="text/javascript">
window.location = 'http://www.sharpturnnetwork.com/forms/success';
</script>
<?php
}
?>
<?php
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
?>
答案 0 :(得分:0)
如果您只是尝试将用户信息传递到另一个PHP页面(http://www.sharpturnnetwork.com/forms/success
),请使用GET参数(例如http://www.sharpturnnetwork.com/forms/success?ip=$ip
)形成URL。但说实话,我并不确定你在问什么。
注意:PHP mail()
会返回TRUE
或FALSE
,但它不会告诉您电子邮件是否已成功发送。这在PHP中是不可能的。
来自mail()
上的PHP文档:
如果邮件成功接受传递,则返回TRUE,FALSE 否则。
重要的是要注意,因为邮件被接受了 交付,并不意味着邮件实际上会达到预期的目的 目的地。