php - 简单的php邮件不发送电子邮件

标签 php email

谁能看看这是否有问题吗?我没有收到任何错误,但从未收到电子邮件。

    <?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/

相关文章:

Java邮件API连接存储在本地服务器但未连接到开发服务器

php - 谷歌地图突然不再工作了

php - 如何在 PHP 中启用数据库自​​动重新连接?

python - Send_mail 未发送邮件至 gmail id。 [ Django ]

java - 如何配置 spring-boot 通过 sendGrid 发送邮件?

php - 如何将所有数据通过电子邮件发送到一封电子邮件中?

c - 如何使用 libetpan 解析电子邮件?

php - 持久连接 : MySQL FOUND_ROWS() results

php - 权限在 PHP 中被拒绝

php - 将 PHP 数组作为数组传递给外部 Javascript 函数