PHP电子邮件表单几乎可以[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在使用带有内置联系表单的HTML5 / CSS模板。我的contact.php文件已经到位,除了最重要的部分外,表格按预期工作。电子邮件未发送。我可能错过了必要的一两行。这是表单和php代码,收件人地址为“[email protected]”,但没有邮件到达收件箱。 greengeeks主机上的php版本为7.2。

<?php
$field_name = $_POST['InputName'];
$field_email = $_POST['InputEmail'];
$field_message = $_POST['InputMessage'];

$mail_to = '[email protected]';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to [email protected]');
        window.location = 'index.html';
    </script>
<?php
}
?>
php html5 forms email contacts
1个回答
0
投票

我试过你的代码,它对我有用吗?只需检查所有内容是否正确发布。你可能错过了一个例子,例如电子邮件地址。

<?php

$field_name = $_POST['InputName'];
$field_email = $_POST['InputEmail'];
$field_message = $_POST['InputMessage'];

$mail_to = '[email protected]';
$subject = 'Message from a site visitor '.$field_name;

$body_message = "From: [from]\nEmail: [emailaddress]\nMessage: [message]";

$headers = 'From: [email protected]'."\r\n";
$headers .= 'Reply-To: [email protected]'."\r\n";

$mail_status = mail($mail_to,$subject,$body_message,$headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to [email protected]');
        window.location = 'index.html';
    </script>
<?php
}
?>
© www.soinside.com 2019 - 2024. All rights reserved.