谁能看看这是否有问题吗?我没有收到任何错误,但从未收到电子邮件。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3bea6bdb4b6b793b6abb2bea3bfb6fdb0bcbe" rel="noreferrer noopener nofollow">[email protected]</a>";
$email_subject = "Email sent through crankapps website";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; // required
$error_message = "";
$email_message = "Form details below.\n\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = "From: ". $name . " <" . $email . ">\n.";
mail($email_to, $email_subject, $email_message, $headers);
?>
最佳答案
首先,仅用一行进行测试:
<?php
mail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95f8e0fbf2f0f1d5f0edf4f8e5f9f0bbf6faf8" rel="noreferrer noopener nofollow">[email protected]</a>', 'test email', 'this is a test');
?>
这很可能行不通。
找出您的 smtp 设置并查看 php.ini 中的 smtp 设置是否与它们匹配。
看看 phpmailer,它可以让您使用更多 smtp 设置,例如 ssl 等。
关于php - 简单的php邮件不发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6461714/