无法使用邮件功能在php中发送邮件

时间:2015-10-23 15:37:41

标签: php

我试图通过php发送邮件,函数邮件返回1,但我没有得到 收件箱中的邮件

if (isset($_POST["firstName"]) == false)
        return;
    $to = "mymail@mail.com";
    $subject = $_POST["subject"];
    $message = $_POST["content"];
    $headers = 'From: ' . $_POST["email"] . "\r\n" .
    'Reply-To: ' .  $_POST["email"] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    $from = "From: " . $_POST["firstName"] . " " . $_POST["lastName"] . " <" . $_POST["email"] . ">";
    echo mail($to, $subject, $message, $headers);
    echo '<script type="text/javascript">alert("sent message succesfully");</script>';

1 个答案:

答案 0 :(得分:-1)

使用PHP的mail()功能是可能的。 请记住邮件功能在本地服务器中不起作用

<?php
$to      = 'abc@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: admin@example.com' . "\r\n" .
   "CC: somebodyelse@example.com";

mail($to, $subject, $message, $headers);
?> 

参考:

http://php.net/manual/en/function.mail.php