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網站。一旦我明天購買域名,我將把它託管在服務器上。 –