我没有收到来自PHP mail()函数的邮件

时间:2020-07-15 06:12:31

标签: php email codeigniter-3

这是我的代码,返回true,但是我没有收到任何邮件。它正在另一个网站上工作。我想检查我的代码是否正常工作。

$name = $this->input->post('name');
$email = $this->input->post('email');
$phone = $this->input->post('phone');
$message = $this->input->post('msg'); 
// Email content

$body = "Hi xxx<br /><br />";
$body.= "Name : " . $name . "<br />";
$body.= "Email : " . $email . "<br />";
$body.= "Phone No : " . $phone . "<br />";

$body.= "Message Placed: " . $message . "<br />";
$body.= "<br />For Enquiry Request</br> ";

    $subject = "Consultation email";
    $to ="xxxxx@xxxxx.in";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From: <'.$email.'>' . "\r\n";
    if(mail($to,$subject,$body,$headers))
    {
    echo '<script>alert("Your message has been sent, our associate will get back to you soon")</script>';
    echo '<script>window.location.href="' . base_url() . '"</script>';
    }
    else{
    
    echo '<script>alert("your message has been not sent")</script>';
    echo "<script>window.location.href='" . base_url() . "'</script>";
    }

1 个答案:

答案 0 :(得分:0)

有几件事情要考虑,其中之一是您不能从本地主机发送电子邮件。可能有解决方法,但通常没有。如果您是从本地主机环境发送邮件,则下面的文章可为您提供帮助

https://www.phpflow.com/php/how-to-send-email-from-localhost-using-php/#:~:text=We%20can%20send%20mail%20from,ini%20file.&text=The%20sendmail%20package%20is%20inbuilt,easily%20send%20mail%20from%20localhost

如果您不在本地环境中,则上一个问题的以下答案似乎有足够的答案来帮助您。

PHP mail function doesn't complete sending of e-mail

此外,您已声明正在使用codeigniter。我认为您在那里缺少一些东西。请查看另一篇文章来修正您的问题。

https://www.cloudways.com/blog/send-email-codeigniter-smtp/

让我知道其中哪一个有所帮助。如果没有,让我知道。