php邮件函数

php邮件函数,php,email,Php,Email,这是我为在localhost上测试邮件功能而编写的代码。 我已经在浏览器中运行了好几次脚本,但仍然没有收到邮箱中的任何电子邮件 我需要其他配置吗 提前谢谢 您需要确保您的PHP安装已设置为使用工作的SMTP服务器。你可能会在里面找到你想要的东西。如果失败,您可能需要在live web服务器上测试脚本。基本上很难从localhost向任何邮件提供商发送邮件。 他们对接收的邮件有很大的限制,而且simply mail()无法工作 您需要使用SMTP服务器。 并在php配置中定义该服务器 <?p

这是我为在localhost上测试邮件功能而编写的代码。 我已经在浏览器中运行了好几次脚本,但仍然没有收到邮箱中的任何电子邮件

我需要其他配置吗


提前谢谢

您需要确保您的PHP安装已设置为使用工作的SMTP服务器。你可能会在里面找到你想要的东西。如果失败,您可能需要在live web服务器上测试脚本。

基本上很难从localhost向任何邮件提供商发送邮件。 他们对接收的邮件有很大的限制,而且simply mail()无法工作

您需要使用SMTP服务器。 并在php配置中定义该服务器

<?php
$sendto = "account@gmail.com";
$subject = "email confirmation"; // Subject 
$message = "the body of the email - this email is to confirm etc...";
# send the email 
mail($sendto, $subject, $message);
?>
如果您没有SMTP服务器,请尝试传递所有标头,如PHP示例中所示:

smtp = localhost  #(here should be your smtp server)
smtp_port = 25

如果您正在使用localhost,我希望它永远不会工作。它将仅在邮件配置的服务器上工作。请试穿一下。


$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
试试这个家伙。这是用来发送邮件的。

试试这个:

 <?php
   $name = $_POST['name'];
    $visitor_email = $_POST['email'];
   $message = $_POST['message'];
 ?>
 <?php
  $email_from = 'yourname@yourwebsite.com';

  $email_subject = "New Form submission";

  $email_body = "You have received a new message from the user $name.\n".
                        "Here is the message:\n $message"
 ?>
 <?php

 $to = "inspiretechpark@gmail.com";

 $headers = "From: $email_from \r\n";

 $headers .= "Reply-To: $visitor_email \r\n";

 mail($to,$email_subject,$email_body,$headers);

 ?>
 <?php
 $to = "name1@website-name.com, name2@website-name.com,name3@website-
 name.com";

  mail($to,$email_subject,$email_body,$headers);
  ?>
<?php
 $to = "name1@website-name.com, name2@website-name.com,name3@website-
 name.com";

  $headers = "From: $email_from \r\n";

  $headers .= "Reply-To: $visitor_email \r\n";

  $headers .= "Cc: someone@domain.com \r\n";

  $headers .= "Bcc: someoneelse@domain.com \r\n";

  mail($to,$email_subject,$email_body,$headers);
  ?>


您确定它没有出现在您的垃圾邮件文件夹中吗?您需要在执行脚本的服务器上运行邮件服务器。只有在运行Windows时,您才需要邮件服务器。是本地主机Windows吗?请检查此项
<?php
    $sender = 'email@example.com';
    $recipient = 'email@example.com';
    $subject = "php mail test";
    $message = "php test message";
    $headers = 'From:' . $sender;
    if (mail($recipient, $subject, $message, $headers))
    {
        echo "Message accepted";
    }
    else
    {
        echo "Error: Message not accepted";
    }
?>