0
我试图建立一个个人投资组合,我希望游客能够与我联系工作机会或问题。我没有做过太多的网站开发工作,所以我有点卡在为什么我不能收到这封电子邮件。这是我正在使用的。发送电子邮件从网站到我的Gmail PHP(405方法不允许)
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
你在哪里测试? – Arkadi
如果您在本地主机上测试,maill()函数被禁用。 在另一个基础上,为什么不使用[PHPMailer](https://github.com/PHPMailer/PHPMailer)? – Nick
我在我的办公室?现在这个网站只是一个github.io网站。一旦我明天购买域名,我将把它托管在服务器上。 –